@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.
- package/CHANGELOG.md +10 -0
- package/dist/adapter.d.ts +12 -5
- package/dist/adapter.js +32 -4
- package/dist/index.d.ts +9 -139
- package/dist/types.d.ts +38 -3
- package/dist/verified-origin/index.d.ts +1 -0
- package/dist/verified-origin/index.js +1 -0
- package/dist/verified-origin/site-path.d.ts +113 -0
- package/dist/verified-origin/site-path.js +179 -0
- package/package.json +23 -9
- package/dist/active-context.d.ts +0 -99
- package/dist/active-context.js +0 -77
- package/dist/agents.d.ts +0 -64
- package/dist/agents.js +0 -23
- package/dist/attachments.d.ts +0 -534
- package/dist/attachments.js +0 -1032
- package/dist/cancel-owned-runs.d.ts +0 -44
- package/dist/cancel-owned-runs.js +0 -35
- package/dist/component-catalog.d.ts +0 -74
- package/dist/component-catalog.js +0 -74
- package/dist/connectors.d.ts +0 -165
- package/dist/connectors.js +0 -474
- package/dist/daemon-status.d.ts +0 -72
- package/dist/daemon-status.js +0 -60
- package/dist/db-ops.d.ts +0 -116
- package/dist/db-ops.js +0 -191
- package/dist/delegated-tools.d.ts +0 -146
- package/dist/delegated-tools.js +0 -286
- package/dist/frontend-control.d.ts +0 -131
- package/dist/frontend-control.js +0 -77
- package/dist/frontend-sessions.d.ts +0 -100
- package/dist/frontend-sessions.js +0 -180
- package/dist/health.d.ts +0 -91
- package/dist/health.js +0 -53
- package/dist/host-tools.d.ts +0 -174
- package/dist/host-tools.js +0 -338
- package/dist/media.d.ts +0 -131
- package/dist/media.js +0 -352
- package/dist/memory.d.ts +0 -230
- package/dist/memory.js +0 -331
- package/dist/model-proxy.d.ts +0 -45
- package/dist/model-proxy.js +0 -619
- package/dist/origin-validation.d.ts +0 -64
- package/dist/origin-validation.js +0 -226
- package/dist/read-only-tools.d.ts +0 -67
- package/dist/read-only-tools.js +0 -59
- package/dist/remote-run-events.d.ts +0 -66
- package/dist/remote-run-events.js +0 -230
- package/dist/research.d.ts +0 -42
- package/dist/research.js +0 -316
- package/dist/route-manifest.d.ts +0 -31
- package/dist/route-manifest.js +0 -103
- package/dist/routines.d.ts +0 -114
- package/dist/routines.js +0 -320
- package/dist/runs.d.ts +0 -79
- package/dist/runs.js +0 -232
- package/dist/terminals.d.ts +0 -125
- package/dist/terminals.js +0 -349
- package/dist/tool-catalog.d.ts +0 -68
- package/dist/tool-catalog.js +0 -68
- package/dist/workspace-root.d.ts +0 -69
- package/dist/workspace-root.js +0 -63
- package/dist/xai.d.ts +0 -86
- package/dist/xai.js +0 -668
package/dist/route-manifest.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module route-manifest
|
|
3
|
-
*
|
|
4
|
-
* Which `{method, path}` pairs each route family mounts, as inert data a caller can read *without*
|
|
5
|
-
* mounting anything.
|
|
6
|
-
*
|
|
7
|
-
* **The problem this solves.** A host that puts a reverse proxy in front of a Jini daemon in another
|
|
8
|
-
* process has to know that daemon's route list to forward anything. With no published inventory, the
|
|
9
|
-
* only way to build one is to copy path strings by hand — and a hand-copied list silently falls behind
|
|
10
|
-
* the moment a family gains a route. That has already happened at least once in a real consumer: a
|
|
11
|
-
* proxy shipped without `GET /api/runs` and the daemon's list endpoint was simply unreachable, 404-ing
|
|
12
|
-
* at the host's own router with nothing to indicate the host was the cause.
|
|
13
|
-
*
|
|
14
|
-
* **Why this file cannot itself drift.** It declares no method or path literals. Every entry is derived
|
|
15
|
-
* from the very `JsonRouteSpec` constant the family's `register*Routes` function mounts, so a spec's
|
|
16
|
-
* path change moves the manifest with it, automatically. The single exception is the SSE run-event
|
|
17
|
-
* route, which is registered with a bare `app.get` rather than a spec — and it contributes the
|
|
18
|
-
* already-exported `RUN_EVENTS_ROUTE_PATH` constant rather than a copy of it.
|
|
19
|
-
*
|
|
20
|
-
* That leaves exactly one failure mode: a family gains a route and nobody adds it *here*. The paired
|
|
21
|
-
* test (`__tests__/route-manifest.test.ts`) closes that by mounting each declared family's real
|
|
22
|
-
* registrar onto a recording app and asserting the manifest matches what actually registered — so a
|
|
23
|
-
* missing entry fails a test rather than reaching a consumer.
|
|
24
|
-
*
|
|
25
|
-
* **Scope, stated honestly: this covers the families a sidecar consumer proxies**, not all 19 the
|
|
26
|
-
* package can mount. {@link routeFamilyManifest} returns `undefined` for anything undeclared rather
|
|
27
|
-
* than an empty list, so "not described here" is distinguishable from "has no routes" — a proxy must
|
|
28
|
-
* never conclude a family is empty when it is merely undocumented. Adding a family is a matter of
|
|
29
|
-
* listing its exported specs below; the test then holds it correct.
|
|
30
|
-
*/
|
|
31
|
-
import { agentListRoute, agentRescanRoute } from './agents.js';
|
|
32
|
-
import { delegatedToolExecuteRoute } from './delegated-tools.js';
|
|
33
|
-
import { apiHealthRoute, apiReadyRoute, apiVersionInfoRoute, healthRoute, readyRoute, versionInfoRoute, } from './health.js';
|
|
34
|
-
import { RUN_EVENTS_ROUTE_PATH, runCancelRoute, runListRoute, runStartRoute, runStatusRoute, } from './runs.js';
|
|
35
|
-
import { toolCatalogDescribeRoute, toolCatalogSearchRoute } from './tool-catalog.js';
|
|
36
|
-
/**
|
|
37
|
-
* Projects route specs onto `RouteRegistration`s, upper-casing the method so entries compare directly
|
|
38
|
-
* against {@link getRouteRegistrationInventory}'s output.
|
|
39
|
-
*
|
|
40
|
-
* @param specs - Route specs, passed by reference so no path literal is ever restated.
|
|
41
|
-
* @returns One registration per spec, in argument order.
|
|
42
|
-
* @complexity O(n) in the number of specs.
|
|
43
|
-
* @overallScore 100/100
|
|
44
|
-
*/
|
|
45
|
-
function fromSpecs(...specs) {
|
|
46
|
-
return specs.map((spec) => ({ method: spec.method.toUpperCase(), path: spec.path }));
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Route families described by this manifest, keyed by the same feature id `@jini-ai/server`'s built-in
|
|
50
|
-
* feature catalog uses — so a host that enables features by name can look routes up by that same name.
|
|
51
|
-
*/
|
|
52
|
-
export const JINI_ROUTE_MANIFEST = {
|
|
53
|
-
health: fromSpecs(healthRoute, apiHealthRoute, readyRoute, apiReadyRoute, versionInfoRoute, apiVersionInfoRoute),
|
|
54
|
-
runs: [
|
|
55
|
-
...fromSpecs(runStartRoute, runListRoute, runStatusRoute, runCancelRoute),
|
|
56
|
-
// Registered with a bare `app.get` rather than a route spec (by `registerRunRoutes` itself), so
|
|
57
|
-
// it contributes its exported path constant instead of a copied literal.
|
|
58
|
-
{ method: 'GET', path: RUN_EVENTS_ROUTE_PATH },
|
|
59
|
-
],
|
|
60
|
-
agents: fromSpecs(agentListRoute, agentRescanRoute),
|
|
61
|
-
toolCatalog: fromSpecs(toolCatalogSearchRoute, toolCatalogDescribeRoute),
|
|
62
|
-
delegatedToolCalls: fromSpecs(delegatedToolExecuteRoute),
|
|
63
|
-
};
|
|
64
|
-
/**
|
|
65
|
-
* The routes one family mounts.
|
|
66
|
-
*
|
|
67
|
-
* @param family - A feature id, e.g. `'runs'`.
|
|
68
|
-
* @returns That family's registrations, or `undefined` when the family is not described by this
|
|
69
|
-
* manifest. The distinction matters: a caller building a proxy allow-list must treat `undefined` as
|
|
70
|
-
* "look it up yourself", never as "this family has no routes" — see this module's scope note.
|
|
71
|
-
* @complexity O(1).
|
|
72
|
-
* @overallScore 100/100
|
|
73
|
-
*/
|
|
74
|
-
export function routeFamilyManifest(family) {
|
|
75
|
-
return JINI_ROUTE_MANIFEST[family];
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Every route across every family this manifest describes, de-duplicated.
|
|
79
|
-
*
|
|
80
|
-
* De-duplication is real rather than defensive: `health` intentionally mounts both `/health` and
|
|
81
|
-
* `/api/health` as separate routes, and a future family could legitimately share a path with another.
|
|
82
|
-
*
|
|
83
|
-
* @param families - Family ids to include. Unknown ids contribute nothing (rather than throwing), so a
|
|
84
|
-
* caller can pass its enabled-feature list verbatim without pre-filtering it.
|
|
85
|
-
* @returns One entry per distinct `METHOD PATH`, in first-seen order.
|
|
86
|
-
* @complexity O(n) in the total routes across the named families.
|
|
87
|
-
* @overallScore 100/100
|
|
88
|
-
*/
|
|
89
|
-
export function manifestRoutesForFamilies(families) {
|
|
90
|
-
const seen = new Set();
|
|
91
|
-
const routes = [];
|
|
92
|
-
for (const family of families) {
|
|
93
|
-
for (const route of JINI_ROUTE_MANIFEST[family] ?? []) {
|
|
94
|
-
const key = `${route.method} ${route.path}`;
|
|
95
|
-
if (seen.has(key))
|
|
96
|
-
continue;
|
|
97
|
-
seen.add(key);
|
|
98
|
-
routes.push(route);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return routes;
|
|
102
|
-
}
|
|
103
|
-
//# sourceMappingURL=route-manifest.js.map
|
package/dist/routines.d.ts
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module routines
|
|
3
|
-
*
|
|
4
|
-
* Routine CRUD + run-history HTTP routes: `GET/POST /api/routines`, `GET/PATCH/DELETE
|
|
5
|
-
* /api/routines/:id`, `POST /api/routines/:id/run`, `GET /api/routines/:id/runs`. Calls into the
|
|
6
|
-
* `RoutineStore`/`RoutineService`-shaped ports `@jini-ai/daemon` ships (see that package's
|
|
7
|
-
* `routines/` module — `routine-store.ts` for the CRUD+history port, `scheduler.ts` for the
|
|
8
|
-
* scheduling engine) the same way `runs.ts` calls into `RunLifecycle` — no business logic lives
|
|
9
|
-
* in this file itself.
|
|
10
|
-
*
|
|
11
|
-
* Ported from OD's `apps/daemon/src/routes/routine.ts` (348 lines, `refactor/web-memory-slice`
|
|
12
|
-
* branch) per the decisions in `ADS-memory/reports/proposals/
|
|
13
|
-
* PROP-http-route-packs-automation-routines-2026-07-21.md` (Finding 2). That proposal identified
|
|
14
|
-
* two separable gaps blocking this route pack: (1) no scheduler existed anywhere in this repo —
|
|
15
|
-
* closed by porting `routines.ts` into `@jini-ai/daemon/src/routines/scheduler.ts` this same pass;
|
|
16
|
-
* (2) no `RoutineStore` persistence port existed for the CRUD side — closed by
|
|
17
|
-
* `@jini-ai/daemon/src/routines/routine-store.ts`, designed the same way `EventLog` is designed.
|
|
18
|
-
* This file is the third piece: the actual HTTP routes, now that both ports exist.
|
|
19
|
-
*
|
|
20
|
-
* **Confirmed bug fixed while porting** (per the proposal's own finding, not carried forward):
|
|
21
|
-
* OD's `GET /api/routines/:id`, `DELETE /api/routines/:id`, and `GET /api/routines/:id/runs` (OD
|
|
22
|
-
* source lines 236/268/292) had no try/catch, unlike every sibling handler in the same file. This
|
|
23
|
-
* port does not reproduce that gap — but not via a per-route try/catch either: every route here
|
|
24
|
-
* is mounted through `adapter.ts`'s `mountJsonRoute`, whose own top-level try/catch already wraps
|
|
25
|
-
* every route's `parse`/`handle` invocation (the same mechanism `runs.ts`/`memory.ts` rely on),
|
|
26
|
-
* so the bug is structurally impossible to reintroduce rather than merely patched at three call
|
|
27
|
-
* sites.
|
|
28
|
-
*
|
|
29
|
-
* **Deliberately NOT ported** (see the proposal's Finding 1 and the "built-in template scoping"
|
|
30
|
-
* decision it required a human call on):
|
|
31
|
-
* - `GET /api/automation-templates` / `GET /api/automation-templates/:id` — these depend on
|
|
32
|
-
* `automation-templates.ts`, which is not ported (see below); none of the routine CRUD/run-now/
|
|
33
|
-
* run-history routes below need it to function.
|
|
34
|
-
* - `POST /api/routines/:id/runs/:runId/crystallize` — depends on `ingestAutomationSource`
|
|
35
|
-
* (`automation-ingestions.ts`), explicitly scoped by the proposal as "a dedicated follow-up
|
|
36
|
-
* task the same size and shape as `@jini-ai/memory`'s own original port," not attempted here.
|
|
37
|
-
* - `automation-templates.ts` itself, including its CRUD-adjacent lookup machinery: the decision
|
|
38
|
-
* already made for this pass is to ship **zero built-in automation templates** (matching this
|
|
39
|
-
* repo's established precedent of keeping product-authored content host-owned — `@jini-ai/memory`'s
|
|
40
|
-
* prompt-composition, `@jini-ai/deploy`'s config-path resolution, etc.) and, since no route in this
|
|
41
|
-
* file needs any part of that module to function, none of it — content or generic shape — is
|
|
42
|
-
* ported this pass.
|
|
43
|
-
* - `automation-proposals.ts` / `automation-ingestions.ts` — untouched, per the proposal's Finding
|
|
44
|
-
* 1 explicit scoping and this task's brief.
|
|
45
|
-
*
|
|
46
|
-
* **Design note — why `target.mode === 'reuse'` project-existence checking is optional, injected
|
|
47
|
-
* DI, not a hard dependency**: OD's original unconditionally called `getProject(db, projectId)`
|
|
48
|
-
* to validate a reuse target. This module has no project concept of its own (matching
|
|
49
|
-
* `active-context.ts`'s `resolveResource` precedent for the same category of coupling), so
|
|
50
|
-
* `RoutineHttpDeps.projectExists` is an optional injected predicate: a host that has a project
|
|
51
|
-
* store supplies it and reuse targets are validated against it exactly like OD did; a host with
|
|
52
|
-
* no such concept (or that wants to defer the check) can omit it, and reuse targets are accepted
|
|
53
|
-
* without existence-checking rather than forcing every consumer to fabricate one.
|
|
54
|
-
*
|
|
55
|
-
* **Design note — why `POST /api/routines/:id/run`'s `run` field can be `null` even on success**:
|
|
56
|
-
* `RoutineStore` deliberately does not record runs (see `routine-store.ts`'s module doc: run
|
|
57
|
-
* *writing* stays the scheduler's own separately-injected `RoutinePersistence` concern, matching
|
|
58
|
-
* OD's own architectural split between the two). This route calls `store.getLatestRun(id)` after
|
|
59
|
-
* `scheduler.runNow(id)` resolves — accurate only if a host has bridged the scheduler's
|
|
60
|
-
* `RoutinePersistence.insertRun`/`updateRun` writes into the same store instance (documented,
|
|
61
|
-
* host-level integration wiring, out of this port's scope, the same way `runs.ts`'s `onStarted`
|
|
62
|
-
* driver is host-supplied). `projectId`/`conversationId`/`agentRunId` on the response always
|
|
63
|
-
* reflect the real, just-started run regardless of that wiring, since those come directly from
|
|
64
|
-
* `scheduler.runNow`'s own return value.
|
|
65
|
-
*/
|
|
66
|
-
import type { Express } from 'express';
|
|
67
|
-
import { type Routine, type RoutineCreateInput, type RoutineRun, type RoutineService, type RoutineStore, type RoutineUpdateInput } from '@jini-ai/daemon';
|
|
68
|
-
import { type AdapterContext } from './adapter.js';
|
|
69
|
-
/** The scheduler surface these routes need — a structural subset of `RoutineService`, matching OD's own `RoutineRoutesService` narrowing (`Pick<RoutineService, 'nextRunAt' | 'rescheduleOne' | 'runNow' | 'unschedule'>`). Wiring a real `RoutineService` in satisfies this with zero adapter code. */
|
|
70
|
-
export type RoutineScheduler = Pick<RoutineService, 'nextRunAt' | 'rescheduleOne' | 'runNow' | 'unschedule'>;
|
|
71
|
-
export interface RoutineHttpDeps {
|
|
72
|
-
readonly store: RoutineStore;
|
|
73
|
-
readonly scheduler: RoutineScheduler;
|
|
74
|
-
/** Validates a `target: {mode: 'reuse', projectId}`'s `projectId` before create/update accept it. Omit to skip existence-checking entirely — see this module's doc comment. */
|
|
75
|
-
readonly projectExists?: (projectId: string) => boolean | Promise<boolean>;
|
|
76
|
-
}
|
|
77
|
-
interface RoutineUpdateRequest {
|
|
78
|
-
readonly id: string;
|
|
79
|
-
readonly patch: RoutineUpdateInput;
|
|
80
|
-
}
|
|
81
|
-
interface RoutineRunsQuery {
|
|
82
|
-
readonly id: string;
|
|
83
|
-
readonly limit: number;
|
|
84
|
-
}
|
|
85
|
-
export interface RoutineListResponse {
|
|
86
|
-
readonly routines: readonly Routine[];
|
|
87
|
-
}
|
|
88
|
-
export declare const routineListRoute: import("./types.js").JsonRouteSpec<void, RoutineListResponse, RoutineHttpDeps>;
|
|
89
|
-
export interface RoutineResponse {
|
|
90
|
-
readonly routine: Routine;
|
|
91
|
-
}
|
|
92
|
-
export declare const routineCreateRoute: import("./types.js").JsonRouteSpec<RoutineCreateInput, RoutineResponse, RoutineHttpDeps>;
|
|
93
|
-
export declare const routineGetRoute: import("./types.js").JsonRouteSpec<string, RoutineResponse, RoutineHttpDeps>;
|
|
94
|
-
export declare const routineUpdateRoute: import("./types.js").JsonRouteSpec<RoutineUpdateRequest, RoutineResponse, RoutineHttpDeps>;
|
|
95
|
-
export interface RoutineDeleteResponse {
|
|
96
|
-
readonly ok: true;
|
|
97
|
-
}
|
|
98
|
-
export declare const routineDeleteRoute: import("./types.js").JsonRouteSpec<string, RoutineDeleteResponse, RoutineHttpDeps>;
|
|
99
|
-
export interface RoutineRunNowResponse {
|
|
100
|
-
readonly routine: Routine | null;
|
|
101
|
-
readonly run: RoutineRun | null;
|
|
102
|
-
readonly projectId: string;
|
|
103
|
-
readonly conversationId: string;
|
|
104
|
-
readonly agentRunId: string;
|
|
105
|
-
}
|
|
106
|
-
export declare const routineRunNowRoute: import("./types.js").JsonRouteSpec<string, RoutineRunNowResponse, RoutineHttpDeps>;
|
|
107
|
-
export interface RoutineRunsResponse {
|
|
108
|
-
readonly runs: readonly RoutineRun[];
|
|
109
|
-
}
|
|
110
|
-
export declare const routineRunsListRoute: import("./types.js").JsonRouteSpec<RoutineRunsQuery, RoutineRunsResponse, RoutineHttpDeps>;
|
|
111
|
-
/** Mounts every routine route on `app`. A pack's `http(app, services)` calls this directly. */
|
|
112
|
-
export declare function registerRoutineRoutes(app: Express, deps: RoutineHttpDeps, adapter: AdapterContext): void;
|
|
113
|
-
export {};
|
|
114
|
-
//# sourceMappingURL=routines.d.ts.map
|
package/dist/routines.js
DELETED
|
@@ -1,320 +0,0 @@
|
|
|
1
|
-
import { validateSchedule, validateTarget, } from '@jini-ai/daemon';
|
|
2
|
-
import { createApiError } from '@jini-ai/protocol';
|
|
3
|
-
import { defineJsonRoute, mountJsonRoute } from './adapter.js';
|
|
4
|
-
import { validationError } from './request.js';
|
|
5
|
-
import { err, ok } from './types.js';
|
|
6
|
-
function isRecord(value) {
|
|
7
|
-
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
8
|
-
}
|
|
9
|
-
function errorMessage(error) {
|
|
10
|
-
return error instanceof Error ? error.message : String(error);
|
|
11
|
-
}
|
|
12
|
-
/** Overlays the scheduler's live `nextRunAt` onto a routine fetched from the store — `RoutineStore` itself has no scheduler knowledge (see `routine-store.ts`'s module doc), matching OD's own `routineFromDb` two-step (fetch, then overlay `routineService.nextRunAt`). */
|
|
13
|
-
function attachNextRunAt(routine, scheduler) {
|
|
14
|
-
return { ...routine, nextRunAt: scheduler.nextRunAt(routine.id)?.getTime() ?? null };
|
|
15
|
-
}
|
|
16
|
-
async function checkTargetProjectExists(target, deps) {
|
|
17
|
-
if (target.mode !== 'reuse' || !deps.projectExists)
|
|
18
|
-
return null;
|
|
19
|
-
const exists = await deps.projectExists(target.projectId);
|
|
20
|
-
return exists ? null : createApiError('NOT_FOUND', `target project ${target.projectId} not found`);
|
|
21
|
-
}
|
|
22
|
-
function parseRoutineId(input) {
|
|
23
|
-
const id = input.params.id;
|
|
24
|
-
return typeof id === 'string' && id.length > 0 ? ok(id) : err(validationError('id must be a non-empty path parameter'));
|
|
25
|
-
}
|
|
26
|
-
function parseNonEmptyString(value, field) {
|
|
27
|
-
if (typeof value !== 'string' || value.trim().length === 0) {
|
|
28
|
-
return err(validationError(`${field} is required`, [{ path: field, message: 'required non-empty string' }]));
|
|
29
|
-
}
|
|
30
|
-
return ok(value.trim());
|
|
31
|
-
}
|
|
32
|
-
/** Present-but-non-string/empty is rejected; absent (`undefined`) or explicit `null` are both accepted (clearing the field on update). */
|
|
33
|
-
function parseOptionalNullableString(body, field) {
|
|
34
|
-
const value = body[field];
|
|
35
|
-
if (value === undefined)
|
|
36
|
-
return ok(undefined);
|
|
37
|
-
if (value === null)
|
|
38
|
-
return ok(null);
|
|
39
|
-
if (typeof value !== 'string' || value.trim().length === 0) {
|
|
40
|
-
return err(validationError(`${field} must be a non-empty string or null when provided`));
|
|
41
|
-
}
|
|
42
|
-
return ok(value);
|
|
43
|
-
}
|
|
44
|
-
function parseSchedule(value) {
|
|
45
|
-
try {
|
|
46
|
-
validateSchedule(value);
|
|
47
|
-
}
|
|
48
|
-
catch (error) {
|
|
49
|
-
return err(validationError(errorMessage(error)));
|
|
50
|
-
}
|
|
51
|
-
return ok(value);
|
|
52
|
-
}
|
|
53
|
-
function parseTarget(value) {
|
|
54
|
-
try {
|
|
55
|
-
validateTarget(value);
|
|
56
|
-
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
return err(validationError(errorMessage(error)));
|
|
59
|
-
}
|
|
60
|
-
return ok(value);
|
|
61
|
-
}
|
|
62
|
-
/** Validates and de-duplicates one `context.*` array field, trimming entries and dropping blanks — mirrors OD's `cleanStringList`. */
|
|
63
|
-
function cleanStringList(value, field) {
|
|
64
|
-
if (!Array.isArray(value))
|
|
65
|
-
return err(validationError(`${field} must be an array`));
|
|
66
|
-
const out = [];
|
|
67
|
-
const seen = new Set();
|
|
68
|
-
for (const item of value) {
|
|
69
|
-
if (typeof item !== 'string')
|
|
70
|
-
return err(validationError(`${field} must contain strings`));
|
|
71
|
-
const trimmed = item.trim();
|
|
72
|
-
if (!trimmed || seen.has(trimmed))
|
|
73
|
-
continue;
|
|
74
|
-
seen.add(trimmed);
|
|
75
|
-
out.push(trimmed);
|
|
76
|
-
}
|
|
77
|
-
return ok(out);
|
|
78
|
-
}
|
|
79
|
-
const CONTEXT_FIELDS = ['skillIds', 'pluginIds', 'mcpServerIds', 'connectorIds'];
|
|
80
|
-
/** Mirrors OD's `normalizeRoutineContext`: an explicitly-empty array for a field is dropped entirely (not kept as `[]`) so a routine's stored context only ever carries fields that actually scope something. */
|
|
81
|
-
function parseContextSelection(value) {
|
|
82
|
-
if (value === undefined || value === null)
|
|
83
|
-
return ok({});
|
|
84
|
-
if (!isRecord(value))
|
|
85
|
-
return err(validationError('context must be an object'));
|
|
86
|
-
const context = {};
|
|
87
|
-
for (const field of CONTEXT_FIELDS) {
|
|
88
|
-
const raw = value[field];
|
|
89
|
-
if (raw === undefined)
|
|
90
|
-
continue;
|
|
91
|
-
const cleaned = cleanStringList(raw, `context.${field}`);
|
|
92
|
-
if (!cleaned.ok)
|
|
93
|
-
return cleaned;
|
|
94
|
-
if (cleaned.value.length > 0)
|
|
95
|
-
context[field] = cleaned.value;
|
|
96
|
-
}
|
|
97
|
-
return ok(context);
|
|
98
|
-
}
|
|
99
|
-
function parseRoutineCreate(input) {
|
|
100
|
-
if (!isRecord(input.body))
|
|
101
|
-
return err(validationError('body must be a JSON object'));
|
|
102
|
-
const name = parseNonEmptyString(input.body.name, 'name');
|
|
103
|
-
if (!name.ok)
|
|
104
|
-
return name;
|
|
105
|
-
const prompt = parseNonEmptyString(input.body.prompt, 'prompt');
|
|
106
|
-
if (!prompt.ok)
|
|
107
|
-
return prompt;
|
|
108
|
-
const schedule = parseSchedule(input.body.schedule);
|
|
109
|
-
if (!schedule.ok)
|
|
110
|
-
return schedule;
|
|
111
|
-
const target = parseTarget(input.body.target);
|
|
112
|
-
if (!target.ok)
|
|
113
|
-
return target;
|
|
114
|
-
const skillId = parseOptionalNullableString(input.body, 'skillId');
|
|
115
|
-
if (!skillId.ok)
|
|
116
|
-
return skillId;
|
|
117
|
-
const agentId = parseOptionalNullableString(input.body, 'agentId');
|
|
118
|
-
if (!agentId.ok)
|
|
119
|
-
return agentId;
|
|
120
|
-
const context = parseContextSelection(input.body.context);
|
|
121
|
-
if (!context.ok)
|
|
122
|
-
return context;
|
|
123
|
-
const enabled = input.body.enabled;
|
|
124
|
-
if (enabled !== undefined && typeof enabled !== 'boolean') {
|
|
125
|
-
return err(validationError('enabled must be a boolean when provided'));
|
|
126
|
-
}
|
|
127
|
-
return ok({
|
|
128
|
-
name: name.value,
|
|
129
|
-
prompt: prompt.value,
|
|
130
|
-
schedule: schedule.value,
|
|
131
|
-
target: target.value,
|
|
132
|
-
...(skillId.value !== undefined ? { skillId: skillId.value } : {}),
|
|
133
|
-
...(agentId.value !== undefined ? { agentId: agentId.value } : {}),
|
|
134
|
-
context: context.value,
|
|
135
|
-
...(enabled !== undefined ? { enabled } : {}),
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
function parseRoutineUpdate(input) {
|
|
139
|
-
const idResult = parseRoutineId(input);
|
|
140
|
-
if (!idResult.ok)
|
|
141
|
-
return idResult;
|
|
142
|
-
if (!isRecord(input.body))
|
|
143
|
-
return err(validationError('body must be a JSON object'));
|
|
144
|
-
const body = input.body;
|
|
145
|
-
// `RoutineUpdateInput`'s fields are `readonly` (an immutable port-input contract) — built here
|
|
146
|
-
// as a mutable local shape field-by-field, then handed back as that readonly type, which is a
|
|
147
|
-
// safe widening (mutable -> readonly), not the reverse.
|
|
148
|
-
const patch = {};
|
|
149
|
-
if (body.name !== undefined) {
|
|
150
|
-
const name = parseNonEmptyString(body.name, 'name');
|
|
151
|
-
if (!name.ok)
|
|
152
|
-
return name;
|
|
153
|
-
patch.name = name.value;
|
|
154
|
-
}
|
|
155
|
-
if (body.prompt !== undefined) {
|
|
156
|
-
const prompt = parseNonEmptyString(body.prompt, 'prompt');
|
|
157
|
-
if (!prompt.ok)
|
|
158
|
-
return prompt;
|
|
159
|
-
patch.prompt = prompt.value;
|
|
160
|
-
}
|
|
161
|
-
if (body.schedule !== undefined) {
|
|
162
|
-
const schedule = parseSchedule(body.schedule);
|
|
163
|
-
if (!schedule.ok)
|
|
164
|
-
return schedule;
|
|
165
|
-
patch.schedule = schedule.value;
|
|
166
|
-
}
|
|
167
|
-
if (body.target !== undefined) {
|
|
168
|
-
const target = parseTarget(body.target);
|
|
169
|
-
if (!target.ok)
|
|
170
|
-
return target;
|
|
171
|
-
patch.target = target.value;
|
|
172
|
-
}
|
|
173
|
-
if (body.skillId !== undefined) {
|
|
174
|
-
const skillId = parseOptionalNullableString(body, 'skillId');
|
|
175
|
-
if (!skillId.ok)
|
|
176
|
-
return skillId;
|
|
177
|
-
patch.skillId = skillId.value ?? null;
|
|
178
|
-
}
|
|
179
|
-
if (body.agentId !== undefined) {
|
|
180
|
-
const agentId = parseOptionalNullableString(body, 'agentId');
|
|
181
|
-
if (!agentId.ok)
|
|
182
|
-
return agentId;
|
|
183
|
-
patch.agentId = agentId.value ?? null;
|
|
184
|
-
}
|
|
185
|
-
if (body.context !== undefined) {
|
|
186
|
-
const context = parseContextSelection(body.context);
|
|
187
|
-
if (!context.ok)
|
|
188
|
-
return context;
|
|
189
|
-
patch.context = context.value;
|
|
190
|
-
}
|
|
191
|
-
if (body.enabled !== undefined) {
|
|
192
|
-
if (typeof body.enabled !== 'boolean')
|
|
193
|
-
return err(validationError('enabled must be a boolean when provided'));
|
|
194
|
-
patch.enabled = body.enabled;
|
|
195
|
-
}
|
|
196
|
-
return ok({ id: idResult.value, patch });
|
|
197
|
-
}
|
|
198
|
-
function parseRoutineRunsQuery(input) {
|
|
199
|
-
const idResult = parseRoutineId(input);
|
|
200
|
-
if (!idResult.ok)
|
|
201
|
-
return idResult;
|
|
202
|
-
const raw = input.query.limit;
|
|
203
|
-
const rawValue = Array.isArray(raw) ? raw[0] : raw;
|
|
204
|
-
// Matches OD's own `Math.min(100, Math.max(1, Number(req.query.limit) || 20))` exactly,
|
|
205
|
-
// including the `|| 20` fallback for NaN/0/negative/absent rather than `?? 20`.
|
|
206
|
-
const numeric = Number(rawValue) || 20;
|
|
207
|
-
const limit = Math.min(100, Math.max(1, numeric));
|
|
208
|
-
return ok({ id: idResult.value, limit });
|
|
209
|
-
}
|
|
210
|
-
export const routineListRoute = defineJsonRoute({
|
|
211
|
-
method: 'get',
|
|
212
|
-
path: '/api/routines',
|
|
213
|
-
parse: () => ok(undefined),
|
|
214
|
-
handle: async (_input, deps) => {
|
|
215
|
-
const routines = await deps.store.list();
|
|
216
|
-
return ok({ routines: routines.map((routine) => attachNextRunAt(routine, deps.scheduler)) });
|
|
217
|
-
},
|
|
218
|
-
});
|
|
219
|
-
export const routineCreateRoute = defineJsonRoute({
|
|
220
|
-
method: 'post',
|
|
221
|
-
path: '/api/routines',
|
|
222
|
-
requireSameOrigin: true,
|
|
223
|
-
parse: parseRoutineCreate,
|
|
224
|
-
handle: async (input, deps) => {
|
|
225
|
-
const targetError = await checkTargetProjectExists(input.target, deps);
|
|
226
|
-
if (targetError)
|
|
227
|
-
return err(targetError);
|
|
228
|
-
const routine = await deps.store.create(input);
|
|
229
|
-
deps.scheduler.rescheduleOne(routine.id);
|
|
230
|
-
return ok({ routine: attachNextRunAt(routine, deps.scheduler) });
|
|
231
|
-
},
|
|
232
|
-
successStatus: 201,
|
|
233
|
-
});
|
|
234
|
-
// ---------------------------------------------------------------------------
|
|
235
|
-
// GET/PATCH/DELETE /api/routines/:id
|
|
236
|
-
// ---------------------------------------------------------------------------
|
|
237
|
-
export const routineGetRoute = defineJsonRoute({
|
|
238
|
-
method: 'get',
|
|
239
|
-
path: '/api/routines/:id',
|
|
240
|
-
parse: parseRoutineId,
|
|
241
|
-
handle: async (id, deps) => {
|
|
242
|
-
const routine = await deps.store.get(id);
|
|
243
|
-
return routine === null
|
|
244
|
-
? err(createApiError('NOT_FOUND', 'routine not found'))
|
|
245
|
-
: ok({ routine: attachNextRunAt(routine, deps.scheduler) });
|
|
246
|
-
},
|
|
247
|
-
});
|
|
248
|
-
export const routineUpdateRoute = defineJsonRoute({
|
|
249
|
-
method: 'patch',
|
|
250
|
-
path: '/api/routines/:id',
|
|
251
|
-
requireSameOrigin: true,
|
|
252
|
-
parse: parseRoutineUpdate,
|
|
253
|
-
handle: async ({ id, patch }, deps) => {
|
|
254
|
-
if (patch.target !== undefined) {
|
|
255
|
-
const targetError = await checkTargetProjectExists(patch.target, deps);
|
|
256
|
-
if (targetError)
|
|
257
|
-
return err(targetError);
|
|
258
|
-
}
|
|
259
|
-
const routine = await deps.store.update(id, patch);
|
|
260
|
-
if (routine === null)
|
|
261
|
-
return err(createApiError('NOT_FOUND', 'routine not found'));
|
|
262
|
-
deps.scheduler.rescheduleOne(id);
|
|
263
|
-
return ok({ routine: attachNextRunAt(routine, deps.scheduler) });
|
|
264
|
-
},
|
|
265
|
-
});
|
|
266
|
-
export const routineDeleteRoute = defineJsonRoute({
|
|
267
|
-
method: 'delete',
|
|
268
|
-
path: '/api/routines/:id',
|
|
269
|
-
requireSameOrigin: true,
|
|
270
|
-
parse: parseRoutineId,
|
|
271
|
-
handle: async (id, deps) => {
|
|
272
|
-
deps.scheduler.unschedule(id);
|
|
273
|
-
const removed = await deps.store.delete(id);
|
|
274
|
-
return removed ? ok({ ok: true }) : err(createApiError('NOT_FOUND', 'routine not found'));
|
|
275
|
-
},
|
|
276
|
-
});
|
|
277
|
-
export const routineRunNowRoute = defineJsonRoute({
|
|
278
|
-
method: 'post',
|
|
279
|
-
path: '/api/routines/:id/run',
|
|
280
|
-
requireSameOrigin: true,
|
|
281
|
-
parse: parseRoutineId,
|
|
282
|
-
handle: async (id, deps) => {
|
|
283
|
-
const existing = await deps.store.get(id);
|
|
284
|
-
if (existing === null)
|
|
285
|
-
return err(createApiError('NOT_FOUND', 'routine not found'));
|
|
286
|
-
const started = await deps.scheduler.runNow(id);
|
|
287
|
-
const [routine, run] = await Promise.all([deps.store.get(id), deps.store.getLatestRun(id)]);
|
|
288
|
-
return ok({
|
|
289
|
-
routine: routine ? attachNextRunAt(routine, deps.scheduler) : null,
|
|
290
|
-
run,
|
|
291
|
-
projectId: started.projectId,
|
|
292
|
-
conversationId: started.conversationId,
|
|
293
|
-
agentRunId: started.agentRunId,
|
|
294
|
-
});
|
|
295
|
-
},
|
|
296
|
-
successStatus: 202,
|
|
297
|
-
});
|
|
298
|
-
export const routineRunsListRoute = defineJsonRoute({
|
|
299
|
-
method: 'get',
|
|
300
|
-
path: '/api/routines/:id/runs',
|
|
301
|
-
parse: parseRoutineRunsQuery,
|
|
302
|
-
handle: async ({ id, limit }, deps) => {
|
|
303
|
-
const existing = await deps.store.get(id);
|
|
304
|
-
if (existing === null)
|
|
305
|
-
return err(createApiError('NOT_FOUND', 'routine not found'));
|
|
306
|
-
const runs = await deps.store.listRuns(id, limit);
|
|
307
|
-
return ok({ runs });
|
|
308
|
-
},
|
|
309
|
-
});
|
|
310
|
-
/** Mounts every routine route on `app`. A pack's `http(app, services)` calls this directly. */
|
|
311
|
-
export function registerRoutineRoutes(app, deps, adapter) {
|
|
312
|
-
mountJsonRoute(app, routineListRoute, deps, adapter);
|
|
313
|
-
mountJsonRoute(app, routineCreateRoute, deps, adapter);
|
|
314
|
-
mountJsonRoute(app, routineGetRoute, deps, adapter);
|
|
315
|
-
mountJsonRoute(app, routineUpdateRoute, deps, adapter);
|
|
316
|
-
mountJsonRoute(app, routineDeleteRoute, deps, adapter);
|
|
317
|
-
mountJsonRoute(app, routineRunNowRoute, deps, adapter);
|
|
318
|
-
mountJsonRoute(app, routineRunsListRoute, deps, adapter);
|
|
319
|
-
}
|
|
320
|
-
//# sourceMappingURL=routines.js.map
|
package/dist/runs.d.ts
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import type { Express } from 'express';
|
|
2
|
-
import { type RunStatus } from '@jini-ai/protocol';
|
|
3
|
-
import type { RunLifecycle } from '@jini-ai/daemon';
|
|
4
|
-
import { type AdapterContext } from './adapter.js';
|
|
5
|
-
import type { ServerResponse } from 'node:http';
|
|
6
|
-
/**
|
|
7
|
-
* Diagnostic detail for an internal-error response the public API deliberately does not
|
|
8
|
-
* disclose (SEC-005): spawn/storage/adapter failures can embed executable paths, working
|
|
9
|
-
* directories, hostnames, or third-party provider text. The correlation id is the only thing
|
|
10
|
-
* that crosses the boundary; the real `error` goes only to this host-owned sink so an operator
|
|
11
|
-
* can still find and act on it.
|
|
12
|
-
*/
|
|
13
|
-
export interface RunInternalErrorContext {
|
|
14
|
-
readonly source: 'run-start' | 'run-stream';
|
|
15
|
-
readonly runId: string;
|
|
16
|
-
readonly correlationId: string;
|
|
17
|
-
readonly error: unknown;
|
|
18
|
-
}
|
|
19
|
-
export interface RunCreateRequest {
|
|
20
|
-
readonly contextRef: string;
|
|
21
|
-
readonly agentId?: string;
|
|
22
|
-
readonly idempotencyKey?: string;
|
|
23
|
-
}
|
|
24
|
-
export interface RunStartContext {
|
|
25
|
-
readonly request: RunCreateRequest;
|
|
26
|
-
readonly run: RunStatus;
|
|
27
|
-
/** The lifecycle this driver must use for emitted events, cancellation observation, and terminal completion. */
|
|
28
|
-
readonly lifecycle: RunLifecycle;
|
|
29
|
-
}
|
|
30
|
-
/** Host-owned execution hook. It attaches a driver only after a durable run has been created. */
|
|
31
|
-
export type RunStartHandler = (context: RunStartContext) => Promise<void> | void;
|
|
32
|
-
export interface RunHttpDeps {
|
|
33
|
-
readonly lifecycle: RunLifecycle;
|
|
34
|
-
readonly onStarted?: RunStartHandler;
|
|
35
|
-
/** Host-owned sink for the real exception behind a generic `INTERNAL_ERROR` response (SEC-005). Defaults to `console.error`. */
|
|
36
|
-
readonly onInternalError?: (context: RunInternalErrorContext) => void;
|
|
37
|
-
}
|
|
38
|
-
export interface RunStartResponse {
|
|
39
|
-
readonly run: RunStatus;
|
|
40
|
-
readonly started: boolean;
|
|
41
|
-
}
|
|
42
|
-
export interface RunStatusResponse {
|
|
43
|
-
readonly run: RunStatus;
|
|
44
|
-
}
|
|
45
|
-
export interface RunCancelResponse {
|
|
46
|
-
readonly run: RunStatus;
|
|
47
|
-
}
|
|
48
|
-
export interface RunListResponse {
|
|
49
|
-
readonly runs: readonly RunStatus[];
|
|
50
|
-
}
|
|
51
|
-
export declare const runStartRoute: import("./types.js").JsonRouteSpec<RunCreateRequest, RunStartResponse, RunHttpDeps>;
|
|
52
|
-
/** `GET /api/runs` — lists runs, optionally scoped to a `contextRef` query parameter. */
|
|
53
|
-
export declare const runListRoute: import("./types.js").JsonRouteSpec<{
|
|
54
|
-
contextRef?: string;
|
|
55
|
-
}, RunListResponse, RunHttpDeps>;
|
|
56
|
-
export declare const runStatusRoute: import("./types.js").JsonRouteSpec<string, RunStatusResponse, RunHttpDeps>;
|
|
57
|
-
export declare const runCancelRoute: import("./types.js").JsonRouteSpec<{
|
|
58
|
-
runId: string;
|
|
59
|
-
reason?: string;
|
|
60
|
-
}, RunCancelResponse, RunHttpDeps>;
|
|
61
|
-
/**
|
|
62
|
-
* The core of `GET /api/runs/:runId/events` — canonical events as SSE, with Last-Event-ID
|
|
63
|
-
* reconnect support. Takes `runId`/`afterCursor` already resolved by the caller. `res` is typed
|
|
64
|
-
* against the raw `node:http` `ServerResponse` rather than Express's own `Response` type — Express's
|
|
65
|
-
* `Response` extends it directly, so this is a no-op widening, the same pattern `run-stream.ts`'s
|
|
66
|
-
* AG-UI handler already established.
|
|
67
|
-
*/
|
|
68
|
-
export declare function handleRunEventStreamRequest(res: ServerResponse, runId: string, afterCursor: string | null, deps: RunHttpDeps): Promise<void>;
|
|
69
|
-
/**
|
|
70
|
-
* Path {@link registerRunEventStream} mounts. Exported as a constant so a caller that needs to know
|
|
71
|
-
* this route exists — a reverse proxy's forward list, `route-manifest.ts` — references it rather than
|
|
72
|
-
* restating the literal and later drifting from it.
|
|
73
|
-
*/
|
|
74
|
-
export declare const RUN_EVENTS_ROUTE_PATH = "/api/runs/:runId/events";
|
|
75
|
-
/** Express mounting glue for {@link handleRunEventStreamRequest} — resolves `runId`/`afterCursor` from an Express `Request` and hands the request straight through. */
|
|
76
|
-
export declare function registerRunEventStream(app: Express, deps: RunHttpDeps): void;
|
|
77
|
-
/** Mounts create/status/cancel JSON endpoints and the SSE event stream as one run transport. */
|
|
78
|
-
export declare function registerRunRoutes(app: Express, deps: RunHttpDeps, adapter: AdapterContext): void;
|
|
79
|
-
//# sourceMappingURL=runs.d.ts.map
|