@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
@@ -1,33 +0,0 @@
1
- /** Canonical links, redirect checks and egress decisions must use stored trust evidence,
2
- * never the raw request Host/:authority, which is attacker-controlled. */
3
- export type OriginScheme = "https" | "http";
4
- export type OriginSource = "workspace-setting" | "dev-capability";
5
- /** Stored trust evidence. Public origins use HTTPS; HTTP is limited to explicit development capabilities. */
6
- export interface VerifiedOrigin {
7
- scheme: OriginScheme;
8
- host: string;
9
- port?: number;
10
- basePath?: string;
11
- verifiedAt: string;
12
- source: OriginSource;
13
- }
14
- export declare class InsecureOriginSourceError extends Error {
15
- constructor({ message }: {
16
- message: string;
17
- });
18
- }
19
- /** Missing trust evidence is a hard precondition failure. Callers must fail closed rather than
20
- * guessing an origin from the request or another unverified value. */
21
- export declare class OriginNotVerifiedError extends Error {
22
- constructor({ message }: {
23
- message: string;
24
- });
25
- }
26
- /** Copy evidence, refusing HTTP public origins and treating public loopback origins as unset.
27
- * Both writers and registry reads use this boundary, including reads of legacy persisted rows.
28
- * @throws InsecureOriginSourceError for HTTP public evidence; OriginNotVerifiedError for loopback public evidence.
29
- * @complexity O(host bytes) time and space; pure, with no ownership or reachability probe.
30
- * @example createVerifiedOrigin({ scheme: "https", host: "example.com", verifiedAt, source: "workspace-setting" });
31
- */
32
- export declare function createVerifiedOrigin(input: VerifiedOrigin, _options?: Record<string, never>): VerifiedOrigin;
33
- //# sourceMappingURL=types.d.ts.map
@@ -1,30 +0,0 @@
1
- import { isLoopbackHost } from "./loopback-host.js";
2
- export class InsecureOriginSourceError extends Error {
3
- constructor({ message }) { super(message); }
4
- }
5
- /** Missing trust evidence is a hard precondition failure. Callers must fail closed rather than
6
- * guessing an origin from the request or another unverified value. */
7
- export class OriginNotVerifiedError extends Error {
8
- constructor({ message }) { super(message); }
9
- }
10
- /** Copy evidence, refusing HTTP public origins and treating public loopback origins as unset.
11
- * Both writers and registry reads use this boundary, including reads of legacy persisted rows.
12
- * @throws InsecureOriginSourceError for HTTP public evidence; OriginNotVerifiedError for loopback public evidence.
13
- * @complexity O(host bytes) time and space; pure, with no ownership or reachability probe.
14
- * @example createVerifiedOrigin({ scheme: "https", host: "example.com", verifiedAt, source: "workspace-setting" });
15
- */
16
- export function createVerifiedOrigin(input, _options = {}) {
17
- // Repositories and other adapters must construct evidence through this function; an object
18
- // literal can bypass the scheme/source invariant even though it satisfies the structural type.
19
- if (input.scheme === "http" && input.source !== "dev-capability") {
20
- throw new InsecureOriginSourceError({
21
- message: `origin scheme 'http' is only legal for source 'dev-capability' (got source '${input.source}')`
22
- });
23
- }
24
- // Explicit dev capabilities may address a listener; a public site URL never may.
25
- if (input.source === "workspace-setting" && isLoopbackHost({ host: input.host })) {
26
- throw new OriginNotVerifiedError({ message: "a loopback host is not a verified public origin" });
27
- }
28
- return { ...input };
29
- }
30
- //# sourceMappingURL=types.js.map
@@ -1,2 +0,0 @@
1
- export * from "./verified-origin/index.js";
2
- //# sourceMappingURL=verified-origin.d.ts.map
@@ -1,2 +0,0 @@
1
- export * from "./verified-origin/index.js";
2
- //# sourceMappingURL=verified-origin.js.map
@@ -1,69 +0,0 @@
1
- /**
2
- * Generic, host-injectable "workspace root" resolution port.
3
- *
4
- * Several OD route packs need the same thing at the boundary: "given some
5
- * opaque resource reference, what filesystem directory does a spawned
6
- * process or launched editor run in?" OD answers that with
7
- * `ctx.projectStore.getProject` + `ctx.projectFiles.resolveProjectDir` — a
8
- * project-store lookup plus a metadata-driven directory resolver, both
9
- * product-specific (see `packages/http/source-map.md`'s routes-classification
10
- * table, rows `#11 terminal.ts` and `#23 host-tools.ts`, both of which name
11
- * exactly this dependency as the reason `POST /api/projects/:id/open-in` and
12
- * the interactive-terminal spawn route were not ported earlier). The kernel
13
- * has no concept of "project," so it cannot hardcode that lookup — but it
14
- * also must not silently invent a directory (guessing `process.cwd()` or an
15
- * OS temp dir would let one request's resource reference leak into an
16
- * unrelated working directory).
17
- *
18
- * Follows the same explicit-injection, conservative-default shape this repo
19
- * already established for `@jini-ai/cli`'s `resolveDaemonUrl`
20
- * (`packages/cli/src/daemon-url.ts`): a host supplies a resolver callback; the
21
- * built-in default resolves nothing and the resolution function throws
22
- * rather than guessing. It also mirrors `active-context.ts`'s
23
- * `resolveResource` DI shape (a caller-supplied lookup replacing OD's
24
- * `getProject`) and its `resourceRef`/`detail` field naming.
25
- */
26
- /** What a route needs resolved: an opaque resource reference, plus an optional sub-locator within it (e.g. a specific file), matching `active-context.ts`'s `resourceRef`/`detail` naming. */
27
- export interface WorkspaceRootRequest {
28
- readonly resourceRef: string;
29
- readonly detail?: string | null;
30
- }
31
- /**
32
- * Host-supplied lookup: given a {@link WorkspaceRootRequest}, return the
33
- * absolute filesystem path a process/editor should be rooted at, or a
34
- * nullish value when this host has no directory for that resource (an
35
- * unknown id, a resource with no on-disk representation, or a caller not
36
- * permitted to resolve it — the resolver decides, the kernel does not).
37
- */
38
- export type WorkspaceRootResolver = (request: WorkspaceRootRequest) => string | null | undefined | Promise<string | null | undefined>;
39
- /** Thrown by {@link resolveWorkspaceRoot} when no root could be resolved — the caller has nothing safe to spawn a process or open an editor against. */
40
- export declare class WorkspaceRootDeniedError extends Error {
41
- readonly resourceRef: string;
42
- constructor(resourceRef: string, reason?: string);
43
- }
44
- /**
45
- * The built-in, zero-config default resolver: resolves nothing, for every
46
- * request. A host that never wires its own resolver gets a hard denial from
47
- * every call site that needs a workspace root — never a guessed path. This
48
- * is the "conservative default that denies rather than guessing" half of
49
- * the port, matching the task's explicit precedent
50
- * (`ToolPolicy`/`resolveDaemonUrl`).
51
- */
52
- export declare const denyAllWorkspaceRoots: WorkspaceRootResolver;
53
- export interface ResolveWorkspaceRootOptions {
54
- /** Defaults to {@link denyAllWorkspaceRoots} — a host must explicitly opt in to resolving real paths. */
55
- readonly resolver?: WorkspaceRootResolver;
56
- }
57
- /**
58
- * Resolves a workspace root for `request` via `options.resolver`.
59
- *
60
- * @throws {WorkspaceRootDeniedError} If the resolver is omitted, or returns
61
- * `null`/`undefined`/an empty string. This function never falls back to a
62
- * guessed path (`process.cwd()`, an OS temp dir, `resourceRef` itself
63
- * treated as a path) — a route that cannot resolve a real root has nothing
64
- * safe to act on.
65
- * @complexity O(1) plus the injected resolver's own cost.
66
- * @overallScore 100/100
67
- */
68
- export declare function resolveWorkspaceRoot(request: WorkspaceRootRequest, options?: ResolveWorkspaceRootOptions): Promise<string>;
69
- //# sourceMappingURL=workspace-root.d.ts.map
@@ -1,63 +0,0 @@
1
- /**
2
- * Generic, host-injectable "workspace root" resolution port.
3
- *
4
- * Several OD route packs need the same thing at the boundary: "given some
5
- * opaque resource reference, what filesystem directory does a spawned
6
- * process or launched editor run in?" OD answers that with
7
- * `ctx.projectStore.getProject` + `ctx.projectFiles.resolveProjectDir` — a
8
- * project-store lookup plus a metadata-driven directory resolver, both
9
- * product-specific (see `packages/http/source-map.md`'s routes-classification
10
- * table, rows `#11 terminal.ts` and `#23 host-tools.ts`, both of which name
11
- * exactly this dependency as the reason `POST /api/projects/:id/open-in` and
12
- * the interactive-terminal spawn route were not ported earlier). The kernel
13
- * has no concept of "project," so it cannot hardcode that lookup — but it
14
- * also must not silently invent a directory (guessing `process.cwd()` or an
15
- * OS temp dir would let one request's resource reference leak into an
16
- * unrelated working directory).
17
- *
18
- * Follows the same explicit-injection, conservative-default shape this repo
19
- * already established for `@jini-ai/cli`'s `resolveDaemonUrl`
20
- * (`packages/cli/src/daemon-url.ts`): a host supplies a resolver callback; the
21
- * built-in default resolves nothing and the resolution function throws
22
- * rather than guessing. It also mirrors `active-context.ts`'s
23
- * `resolveResource` DI shape (a caller-supplied lookup replacing OD's
24
- * `getProject`) and its `resourceRef`/`detail` field naming.
25
- */
26
- /** Thrown by {@link resolveWorkspaceRoot} when no root could be resolved — the caller has nothing safe to spawn a process or open an editor against. */
27
- export class WorkspaceRootDeniedError extends Error {
28
- resourceRef;
29
- constructor(resourceRef, reason) {
30
- super(reason ?? `no workspace root available for resource "${resourceRef}"`);
31
- this.name = 'WorkspaceRootDeniedError';
32
- this.resourceRef = resourceRef;
33
- }
34
- }
35
- /**
36
- * The built-in, zero-config default resolver: resolves nothing, for every
37
- * request. A host that never wires its own resolver gets a hard denial from
38
- * every call site that needs a workspace root — never a guessed path. This
39
- * is the "conservative default that denies rather than guessing" half of
40
- * the port, matching the task's explicit precedent
41
- * (`ToolPolicy`/`resolveDaemonUrl`).
42
- */
43
- export const denyAllWorkspaceRoots = () => null;
44
- /**
45
- * Resolves a workspace root for `request` via `options.resolver`.
46
- *
47
- * @throws {WorkspaceRootDeniedError} If the resolver is omitted, or returns
48
- * `null`/`undefined`/an empty string. This function never falls back to a
49
- * guessed path (`process.cwd()`, an OS temp dir, `resourceRef` itself
50
- * treated as a path) — a route that cannot resolve a real root has nothing
51
- * safe to act on.
52
- * @complexity O(1) plus the injected resolver's own cost.
53
- * @overallScore 100/100
54
- */
55
- export async function resolveWorkspaceRoot(request, options = {}) {
56
- const resolver = options.resolver ?? denyAllWorkspaceRoots;
57
- const root = await resolver(request);
58
- if (typeof root !== 'string' || root.length === 0) {
59
- throw new WorkspaceRootDeniedError(request.resourceRef);
60
- }
61
- return root;
62
- }
63
- //# sourceMappingURL=workspace-root.js.map
package/dist/xai.d.ts DELETED
@@ -1,86 +0,0 @@
1
- import type { Express } from 'express';
2
- import { PendingAuthCache, startOAuthCallbackListener, type OAuthCallbackListener, type OAuthPkceProviderConfig } from '@jini-ai/agent-runtime';
3
- import { type AdapterContext } from './adapter.js';
4
- export interface XaiInternalErrorContext {
5
- readonly source: 'oauth-start' | 'oauth-complete' | 'oauth-disconnect' | 'auth-status' | 'search';
6
- readonly correlationId: string;
7
- readonly error: unknown;
8
- }
9
- export interface XaiHttpDeps {
10
- /** Directory the xAI OAuth token is persisted under (`<dataDir>/<tokenFileName>`). Defaults to `process.cwd()` — a host with a real dataDir should override this (matching `create-local-node-daemon.ts`'s `memoryRoutesDeps.dataDir` pattern). */
11
- readonly dataDir?: string;
12
- /** On-disk file name for the stored token, scoped under `dataDir`. Defaults to `xai-oauth-token.json`. */
13
- readonly tokenFileName?: string;
14
- /** The OAuth+PKCE provider config to drive the dance against. Defaults to `@jini-ai/agent-runtime`'s real `XAI_OAUTH_PROVIDER_CONFIG` preset — override only to point at a different client_id/issuer (e.g. once a non-PoC xAI client_id is provisioned). */
15
- readonly providerConfig?: OAuthPkceProviderConfig;
16
- /** Loopback callback host `providerConfig.clientId` is registered against. Defaults to `XAI_OAUTH_REDIRECT_HOST` (`127.0.0.1`) — see module doc on why this is fixed for xAI's PoC client_id. */
17
- readonly callbackHost?: string;
18
- /** Loopback callback port `providerConfig.clientId` is registered against. Defaults to `XAI_OAUTH_REDIRECT_PORT` (`56121`). */
19
- readonly callbackPort?: number;
20
- /** Loopback callback path `providerConfig.clientId` is registered against. Defaults to `XAI_OAUTH_REDIRECT_PATH` (`/callback`). */
21
- readonly callbackPath?: string;
22
- /** In-memory pending-authorization cache backing the begin/complete dance. Defaults to a fresh 30-minute `PendingAuthCache`, shared across every request `registerXaiRoutes` mounts — see module doc on why this must be resolved once, not per-call. */
23
- readonly pending?: PendingAuthCache;
24
- /** Mutable slot holding the in-flight loopback listener, if any (only one OAuth dance can be in flight at a time — the port is a singleton). Shared the same way `pending` is. Defaults to `{ current: null }`. */
25
- readonly listenerRef?: {
26
- current: OAuthCallbackListener | null;
27
- };
28
- /** Opens the loopback callback listener. Defaults to `@jini-ai/agent-runtime`'s `startOAuthCallbackListener`. Overridable so tests never bind a real socket. */
29
- readonly startCallbackListener?: typeof startOAuthCallbackListener;
30
- /** Base URL for xAI's Responses API (`POST {searchBaseUrl}/responses`). Defaults to `https://api.x.ai/v1`. */
31
- readonly searchBaseUrl?: string;
32
- /** Model id sent to the Responses API when a search request doesn't supply its own. Defaults to xAI's real `grok-4.20-reasoning`. */
33
- readonly searchDefaultModel?: string;
34
- readonly fetchImpl?: typeof fetch;
35
- /** Deadline for one search request *and* its response body, in milliseconds. Defaults to {@link DEFAULT_SEARCH_TIMEOUT_MS}. */
36
- readonly searchTimeoutMs?: number;
37
- /** Host-owned sink for the real exception behind a generic `INTERNAL_ERROR` response (SEC-005). Defaults to `console.error`. */
38
- readonly onInternalError?: (context: XaiInternalErrorContext) => void;
39
- }
40
- export interface XaiOauthStartResponse {
41
- readonly authorizeUrl: string;
42
- readonly state: string;
43
- readonly callback: {
44
- readonly host: string;
45
- readonly port: number;
46
- };
47
- }
48
- export declare const xaiOauthStartRoute: import("./types.js").JsonRouteSpec<void, XaiOauthStartResponse, XaiHttpDeps>;
49
- export interface XaiOkResponse {
50
- readonly ok: true;
51
- }
52
- interface XaiOauthCompleteRequest {
53
- readonly state: string;
54
- readonly code: string;
55
- }
56
- export declare const xaiOauthCompleteRoute: import("./types.js").JsonRouteSpec<XaiOauthCompleteRequest, XaiOkResponse, XaiHttpDeps>;
57
- export declare const xaiOauthCancelRoute: import("./types.js").JsonRouteSpec<void, XaiOkResponse, XaiHttpDeps>;
58
- export interface XaiAuthStatusResponse {
59
- readonly connected: boolean;
60
- readonly expiresAt: number | null;
61
- readonly scope: string | null;
62
- readonly savedAt: number | null;
63
- readonly listening: boolean;
64
- }
65
- export declare const xaiAuthStatusRoute: import("./types.js").JsonRouteSpec<void, XaiAuthStatusResponse, XaiHttpDeps>;
66
- export declare const xaiOauthDisconnectRoute: import("./types.js").JsonRouteSpec<void, XaiOkResponse, XaiHttpDeps>;
67
- interface XaiSearchRequest {
68
- readonly query: string;
69
- readonly allowedXHandles?: readonly string[];
70
- readonly excludedXHandles?: readonly string[];
71
- readonly fromDate?: string;
72
- readonly toDate?: string;
73
- readonly enableImageUnderstanding?: boolean;
74
- readonly enableVideoUnderstanding?: boolean;
75
- readonly model?: string;
76
- }
77
- export interface XaiSearchResponse {
78
- readonly answer: string;
79
- readonly citations: readonly string[];
80
- readonly model: string;
81
- }
82
- export declare const xaiSearchRoute: import("./types.js").JsonRouteSpec<XaiSearchRequest, XaiSearchResponse, XaiHttpDeps>;
83
- /** Mounts every xAI route on `app`. A pack's `http(app, services)` calls this directly. */
84
- export declare function registerXaiRoutes(app: Express, deps: XaiHttpDeps, adapter: AdapterContext): void;
85
- export {};
86
- //# sourceMappingURL=xai.d.ts.map