@valerypopoff/rivet2-cli 2.0.11 → 2.1.0

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.
@@ -0,0 +1,99 @@
1
+ import { createRivetWebAppHandler } from '@valerypopoff/rivet2-node';
2
+ import chalk from 'chalk';
3
+ import { configDotenv } from 'dotenv';
4
+ import { Hono } from 'hono';
5
+ import { addDatasetOptions, addProviderOptions, loadProjectRuntime, resolveUiGraph, warnIfServerSavesDatasets, withCliProcessorOptions, } from '../cliRuntime.js';
6
+ import { addHttpOptions, createHttpMiddleware, formatListenUrl, jsonErrorResponse, startHttpServer, } from '../http.js';
7
+ export function makeCommand(y) {
8
+ const command = addHttpOptions(addProviderOptions(y)
9
+ .positional('projectFile', {
10
+ describe: 'The project file containing the Rivet web app',
11
+ type: 'string',
12
+ demandOption: true,
13
+ })
14
+ .positional('uiGraph', {
15
+ describe: 'The web app name or ID to serve. If omitted, the only web app in the project is used.',
16
+ type: 'string',
17
+ })
18
+ .option('port', {
19
+ describe: 'The port to serve on',
20
+ type: 'number',
21
+ default: 3000,
22
+ })
23
+ .option('host', {
24
+ describe: 'The host interface to bind to',
25
+ type: 'string',
26
+ default: '0.0.0.0',
27
+ })
28
+ .option('base-path', {
29
+ describe: 'The URL base path where the web app is mounted',
30
+ type: 'string',
31
+ default: '/',
32
+ })
33
+ .option('dev', {
34
+ describe: 'Run in development mode: rereads the project file on each request',
35
+ type: 'boolean',
36
+ default: false,
37
+ })
38
+ .option('revision-key', {
39
+ describe: 'Opaque revision key embedded in HTML and checked on action requests',
40
+ type: 'string',
41
+ }));
42
+ return addDatasetOptions(command);
43
+ }
44
+ export async function serveApp(args) {
45
+ configDotenv();
46
+ const { app, projectFilePath, uiGraphName } = await createWebAppServeApp(args);
47
+ startHttpServer(app, args.host, args.port);
48
+ console.log(chalk.green(`Serving Rivet web app "${chalk.bold.white(uiGraphName)}" from ${chalk.bold.white(projectFilePath)} at ${chalk.bold.white(formatListenUrl(args.host, args.port))}.`));
49
+ }
50
+ export async function createWebAppServeApp(args) {
51
+ throwIfReservedBasePath(args.basePath);
52
+ const runtime = await loadProjectRuntime(args.projectFile, args);
53
+ const uiGraph = resolveUiGraph(runtime.project, args.uiGraph);
54
+ const staticHandler = args.dev ? undefined : createHandler(runtime, args, uiGraph.id);
55
+ warnIfWebAppBearerTokenIsConfigured(args);
56
+ warnIfServerSavesDatasets(args.saveDatasets, 'CLI web-app server');
57
+ const app = new Hono();
58
+ app.use('*', createHttpMiddleware(args));
59
+ app.get('/healthz', (c) => c.json({
60
+ ok: true,
61
+ projectPath: runtime.projectPath,
62
+ uiGraphId: uiGraph.id,
63
+ }));
64
+ app.all('*', async (c) => {
65
+ const startedAt = Date.now();
66
+ try {
67
+ const handler = staticHandler ?? createHandler(await loadProjectRuntime(args.projectFile, args), args, uiGraph.id);
68
+ return handler.handleRequest(c.req.raw);
69
+ }
70
+ catch (error) {
71
+ return jsonErrorResponse(c, error, startedAt, 500);
72
+ }
73
+ });
74
+ return {
75
+ app,
76
+ projectFilePath: runtime.projectPath,
77
+ uiGraphName: uiGraph.name,
78
+ };
79
+ }
80
+ function createHandler(runtime, args, uiGraphId = resolveUiGraph(runtime.project, args.uiGraph).id) {
81
+ return createRivetWebAppHandler(runtime.project, {
82
+ basePath: args.basePath,
83
+ createProcessorOptions: () => withCliProcessorOptions(runtime, args, {}),
84
+ revisionKey: args.revisionKey,
85
+ uiGraphId,
86
+ });
87
+ }
88
+ function throwIfReservedBasePath(basePath) {
89
+ const normalizedBasePath = `/${basePath}`.replace(/\/+/g, '/').replace(/\/$/, '');
90
+ if (normalizedBasePath === '/healthz') {
91
+ throw new Error('--base-path /healthz is reserved for the CLI health endpoint.');
92
+ }
93
+ }
94
+ function warnIfWebAppBearerTokenIsConfigured(args) {
95
+ if (!args.bearerToken && !process.env.RIVET_CLI_BEARER_TOKEN) {
96
+ return;
97
+ }
98
+ console.warn(chalk.yellow('serve-app bearer-token auth expects clients to send Authorization headers. Browser navigation to the app HTML cannot add that header by itself; use a reverse proxy or cookie auth for browser-facing deployments.'));
99
+ }
package/bin/http.js ADDED
@@ -0,0 +1,107 @@
1
+ import { serve as serveHono } from '@hono/node-server';
2
+ export class CliHttpError extends Error {
3
+ status;
4
+ constructor(message, status = 400) {
5
+ super(message);
6
+ this.status = status;
7
+ this.name = 'CliHttpError';
8
+ }
9
+ }
10
+ export function addHttpOptions(y) {
11
+ return y
12
+ .option('bearer-token', {
13
+ describe: 'Require Authorization: Bearer <token>. Defaults to RIVET_CLI_BEARER_TOKEN.',
14
+ type: 'string',
15
+ })
16
+ .option('cors-origin', {
17
+ describe: 'Allow a CORS origin. Can be repeated, or set to *.',
18
+ type: 'string',
19
+ array: true,
20
+ default: [],
21
+ });
22
+ }
23
+ export function createHttpMiddleware({ bearerToken, corsOrigin = [] }) {
24
+ const effectiveBearerToken = bearerToken ?? process.env.RIVET_CLI_BEARER_TOKEN;
25
+ return async (c, next) => {
26
+ applyCorsHeaders(c, corsOrigin);
27
+ if (c.req.method === 'OPTIONS' && corsOrigin.length > 0) {
28
+ return c.body(null, 204);
29
+ }
30
+ if (c.req.path !== '/healthz' && effectiveBearerToken) {
31
+ const authorization = c.req.header('authorization');
32
+ if (authorization !== `Bearer ${effectiveBearerToken}`) {
33
+ return c.json({
34
+ error: {
35
+ message: 'Unauthorized.',
36
+ name: 'Unauthorized',
37
+ },
38
+ durationMs: 0,
39
+ }, 401);
40
+ }
41
+ }
42
+ await next();
43
+ applyCorsHeaders(c, corsOrigin);
44
+ };
45
+ }
46
+ export function jsonErrorResponse(c, error, startedAt, fallbackStatus = 500) {
47
+ const status = error instanceof CliHttpError ? error.status : fallbackStatus;
48
+ const durationMs = Math.max(0, Date.now() - startedAt);
49
+ c.header('x-duration-ms', String(durationMs));
50
+ return c.json({
51
+ error: {
52
+ message: error instanceof Error ? error.message : String(error),
53
+ name: error instanceof Error ? error.name : 'Error',
54
+ },
55
+ durationMs,
56
+ }, toCliJsonStatus(status));
57
+ }
58
+ export function jsonTimedResponse(c, payload, startedAt) {
59
+ c.header('x-duration-ms', String(Math.max(0, Date.now() - startedAt)));
60
+ return c.json(payload);
61
+ }
62
+ export function formatListenUrl(host, port) {
63
+ const displayHost = host.includes(':') && !host.startsWith('[') ? `[${host}]` : host;
64
+ return `http://${displayHost}:${port}`;
65
+ }
66
+ export function startHttpServer(app, host, port) {
67
+ const server = serveHono({
68
+ fetch: app.fetch,
69
+ hostname: host,
70
+ port,
71
+ });
72
+ function shutdown() {
73
+ console.log('Shutting down...');
74
+ server.close((err) => {
75
+ if (err) {
76
+ console.error(err);
77
+ process.exit(1);
78
+ }
79
+ process.exit(0);
80
+ });
81
+ }
82
+ process.on('SIGINT', shutdown);
83
+ process.on('SIGTERM', shutdown);
84
+ }
85
+ function applyCorsHeaders(c, corsOrigins) {
86
+ if (corsOrigins.length === 0) {
87
+ return;
88
+ }
89
+ const requestOrigin = c.req.header('origin');
90
+ const allowedOrigin = resolveAllowedOrigin(corsOrigins, requestOrigin);
91
+ if (!allowedOrigin) {
92
+ return;
93
+ }
94
+ c.header('access-control-allow-origin', allowedOrigin);
95
+ c.header('access-control-allow-methods', 'GET,POST,OPTIONS');
96
+ c.header('access-control-allow-headers', 'content-type,authorization');
97
+ c.header('vary', 'Origin');
98
+ }
99
+ function resolveAllowedOrigin(corsOrigins, requestOrigin) {
100
+ if (corsOrigins.includes('*')) {
101
+ return '*';
102
+ }
103
+ return requestOrigin && corsOrigins.includes(requestOrigin) ? requestOrigin : undefined;
104
+ }
105
+ function toCliJsonStatus(status) {
106
+ return status === 400 || status === 401 || status === 404 || status === 409 || status === 500 ? status : 500;
107
+ }
package/bin/output.js ADDED
@@ -0,0 +1,32 @@
1
+ import { writeFile } from 'node:fs/promises';
2
+ import { resolve } from 'node:path';
3
+ export function shapeOutputs(outputs, options) {
4
+ validateOutputShapeOptions(options);
5
+ const { includeCost = false, outputKey, unwrapOutput } = options;
6
+ const visibleOutputs = { ...outputs };
7
+ if (!includeCost) {
8
+ delete visibleOutputs.cost;
9
+ }
10
+ const selectedOutputKey = unwrapOutput ?? outputKey;
11
+ if (!selectedOutputKey) {
12
+ return visibleOutputs;
13
+ }
14
+ if (!Object.prototype.hasOwnProperty.call(visibleOutputs, selectedOutputKey)) {
15
+ throw new Error(`Output "${selectedOutputKey}" was not returned by the graph.`);
16
+ }
17
+ const selectedOutput = visibleOutputs[selectedOutputKey];
18
+ return unwrapOutput ? selectedOutput?.value : selectedOutput;
19
+ }
20
+ export function validateOutputShapeOptions({ outputKey, unwrapOutput }) {
21
+ if (outputKey && unwrapOutput) {
22
+ throw new Error('Use only one output selector. Received: --output-key, --unwrap-output.');
23
+ }
24
+ }
25
+ export async function writeJsonOutput(payload, outputFile) {
26
+ const json = `${JSON.stringify(payload, null, 2)}\n`;
27
+ if (outputFile) {
28
+ await writeFile(resolve(process.cwd(), outputFile), json, 'utf8');
29
+ return;
30
+ }
31
+ process.stdout.write(json);
32
+ }
@@ -0,0 +1,47 @@
1
+ import { NodeDatasetProvider, type NodeCreateProcessorOptions, type Project, type UiGraph } from '@valerypopoff/rivet2-node';
2
+ import type * as yargs from 'yargs';
3
+ export type DatasetCliOptions = {
4
+ datasetFile?: string;
5
+ requireDatasetFile?: boolean;
6
+ saveDatasets?: boolean;
7
+ };
8
+ export type ProviderCliOptions = {
9
+ openaiApiKey?: string;
10
+ openaiEndpoint?: string;
11
+ openaiOrganization?: string;
12
+ };
13
+ export type LoadedProjectRuntime = {
14
+ datasetProvider: NodeDatasetProvider;
15
+ project: Project;
16
+ projectPath: string;
17
+ };
18
+ export type GraphSummary = {
19
+ id: string;
20
+ name: string;
21
+ };
22
+ export type UiGraphSummary = {
23
+ id: string;
24
+ name: string;
25
+ };
26
+ type GraphArgumentStyle = 'option' | 'positional';
27
+ export declare function loadProjectRuntime(projectFile: string | undefined, datasetOptions: DatasetCliOptions): Promise<LoadedProjectRuntime>;
28
+ export declare function createDatasetProvider(projectPath: string, { datasetFile, requireDatasetFile, saveDatasets }: DatasetCliOptions): Promise<NodeDatasetProvider>;
29
+ export declare function resolveDatasetFilePath(projectPath: string, datasetFile?: string): string;
30
+ export declare function withRuntimeProcessorOptions(runtime: Pick<LoadedProjectRuntime, 'datasetProvider' | 'projectPath'>, options: Omit<NodeCreateProcessorOptions, 'datasetProvider' | 'projectPath'>): NodeCreateProcessorOptions;
31
+ export declare function withCliProcessorOptions(runtime: Pick<LoadedProjectRuntime, 'datasetProvider' | 'projectPath'>, providerOptions: ProviderCliOptions, options: Omit<NodeCreateProcessorOptions, 'datasetProvider' | 'openAiEndpoint' | 'openAiKey' | 'openAiOrganization' | 'projectPath'>): NodeCreateProcessorOptions;
32
+ export declare function withProviderProcessorOptions(providerOptions: ProviderCliOptions, options: Omit<NodeCreateProcessorOptions, 'openAiEndpoint' | 'openAiKey' | 'openAiOrganization'>): NodeCreateProcessorOptions;
33
+ export declare function addProviderOptions<T>(y: yargs.Argv<T>): yargs.Argv<T>;
34
+ export declare function addDatasetOptions<T>(y: yargs.Argv<T>, { includeSaveDatasets }?: {
35
+ includeSaveDatasets?: boolean;
36
+ }): yargs.Argv<T>;
37
+ export declare function warnIfServerSavesDatasets(saveDatasets: boolean | undefined, label?: string): void;
38
+ export declare function getGraphSummaries(project: Project): GraphSummary[];
39
+ export declare function findGraph(project: Project, graphIdOrName: string | undefined): GraphSummary | undefined;
40
+ export declare function formatGraphList(project: Project): string;
41
+ export declare function resolveServedGraphName(project: Project, graph: string | undefined): string;
42
+ export declare function throwIfNoMainGraph(project: Project, graph: string | undefined, projectFilePath: string, argumentStyle?: GraphArgumentStyle): void;
43
+ export declare function throwIfInvalidGraph(project: Project, graph: string | undefined, argumentStyle?: GraphArgumentStyle): void;
44
+ export declare function getUiGraphSummaries(project: Project): UiGraphSummary[];
45
+ export declare function resolveUiGraph(project: Project, uiGraphIdOrName: string | undefined): UiGraph;
46
+ export declare function getProjectFile(initialProjectFilePath: string | undefined): Promise<string>;
47
+ export {};
@@ -1,3 +1,9 @@
1
- import type { LooseDataValue } from '@valerypopoff/rivet2-node';
1
+ import { type LooseDataValue } from '@valerypopoff/rivet2-node';
2
2
  export declare function parseJsonInputRecord(text: string, source: string): Record<string, LooseDataValue>;
3
3
  export declare function parseKeyValueInputRecord(values: string[], source: string): Record<string, LooseDataValue>;
4
+ export declare function parseJsonKeyValueInputRecord(values: string[], source: string): Record<string, LooseDataValue>;
5
+ export declare function parseJsonInputRecordFromFile(filePath: string, source: string): Promise<Record<string, LooseDataValue>>;
6
+ export declare function throwIfConflictingInputSources(sources: Array<{
7
+ enabled: boolean;
8
+ name: string;
9
+ }>, sourceKind: string): void;
@@ -0,0 +1,28 @@
1
+ import type * as yargs from 'yargs';
2
+ import { type DatasetCliOptions } from '../cliRuntime.js';
3
+ export type DoctorArgs = {
4
+ json: boolean;
5
+ projectFile: string;
6
+ } & DatasetCliOptions;
7
+ export type DoctorCheckStatus = 'ok' | 'warning' | 'error';
8
+ export type DoctorCheck = {
9
+ id: string;
10
+ message: string;
11
+ status: DoctorCheckStatus;
12
+ };
13
+ export type DoctorReport = {
14
+ checks: DoctorCheck[];
15
+ ok: boolean;
16
+ path: string;
17
+ summary: {
18
+ errors: number;
19
+ warnings: number;
20
+ };
21
+ };
22
+ export declare function makeDoctorCommand<T>(y: yargs.Argv<T>): yargs.Argv<T & {
23
+ projectFile: string;
24
+ } & {
25
+ json: boolean;
26
+ }>;
27
+ export declare function doctor(args: DoctorArgs): Promise<void>;
28
+ export declare function buildDoctorReport(projectFile: string, options?: DatasetCliOptions): Promise<DoctorReport>;
@@ -0,0 +1,44 @@
1
+ import { type Project } from '@valerypopoff/rivet2-node';
2
+ import type * as yargs from 'yargs';
3
+ export type ProjectListArgs = {
4
+ json: boolean;
5
+ projectFile: string;
6
+ };
7
+ export declare function makeListCommand<T>(y: yargs.Argv<T>): yargs.Argv<T & {
8
+ projectFile: string;
9
+ } & {
10
+ json: boolean;
11
+ }>;
12
+ export declare function makeInspectCommand<T>(y: yargs.Argv<T>): yargs.Argv<T & {
13
+ projectFile: string;
14
+ }>;
15
+ export declare function list(args: ProjectListArgs): Promise<void>;
16
+ export declare function inspect(projectFile: string): Promise<void>;
17
+ export type ProjectInspection = {
18
+ graphs: Array<{
19
+ id: string;
20
+ main: boolean;
21
+ name: string;
22
+ nodes: number;
23
+ }>;
24
+ libraryNodes: Array<{
25
+ id: string;
26
+ nodeType: string;
27
+ title: string;
28
+ }>;
29
+ path: string;
30
+ plugins: NonNullable<Project['plugins']>;
31
+ project: {
32
+ description?: string;
33
+ id: string;
34
+ mainGraphId?: string;
35
+ title: string;
36
+ };
37
+ webApps: Array<{
38
+ components: number;
39
+ id: string;
40
+ name: string;
41
+ }>;
42
+ };
43
+ export declare function inspectProject(projectFile: string): Promise<ProjectInspection>;
44
+ export declare function buildProjectInspection(project: Project, projectPath: string): ProjectInspection;
@@ -1,22 +1,46 @@
1
1
  import type * as yargs from 'yargs';
2
+ import { type DatasetCliOptions, type ProviderCliOptions } from '../cliRuntime.js';
3
+ type RunArgs = {
4
+ context: string[];
5
+ contextFile: string | undefined;
6
+ contextJson: string[];
7
+ graphName: string | undefined;
8
+ includeCost: boolean;
9
+ input: string[];
10
+ inputJson: string[];
11
+ inputsFile: string | undefined;
12
+ inputsStdin: boolean;
13
+ outputFile: string | undefined;
14
+ outputKey: string | undefined;
15
+ projectFile: string;
16
+ unwrapOutput: string | undefined;
17
+ } & DatasetCliOptions & ProviderCliOptions;
2
18
  export declare function makeCommand<T>(y: yargs.Argv<T>): yargs.Argv<T & {
3
19
  projectFile: string;
4
20
  } & {
5
21
  graphName: string | undefined;
6
22
  } & {
7
23
  "inputs-stdin": boolean;
24
+ } & {
25
+ "inputs-file": string | undefined;
26
+ } & {
27
+ "input-json": string[] | never[];
8
28
  } & {
9
29
  "include-cost": boolean;
30
+ } & {
31
+ "output-key": string | undefined;
32
+ } & {
33
+ "unwrap-output": string | undefined;
34
+ } & {
35
+ "output-file": string | undefined;
10
36
  } & {
11
37
  context: string[] | never[];
38
+ } & {
39
+ "context-json": string[] | never[];
40
+ } & {
41
+ "context-file": string | undefined;
12
42
  } & {
13
43
  input: string[] | never[];
14
44
  }>;
15
- export declare function run(args: {
16
- projectFile: string;
17
- graphName: string | undefined;
18
- inputsStdin: boolean;
19
- includeCost: boolean;
20
- context: string[];
21
- input: string[];
22
- }): Promise<void>;
45
+ export declare function run(args: RunArgs): Promise<void>;
46
+ export {};
@@ -1,30 +1,40 @@
1
1
  import type { LooseDataValue, NodeCreateProcessorOptions, Project, RivetEventStreamFilterSpec } from '@valerypopoff/rivet2-node';
2
+ import { Hono } from 'hono';
2
3
  import type * as yargs from 'yargs';
3
- type ServeArgs = {
4
- port: number;
5
- projectFile: string | undefined;
6
- dev: boolean;
7
- graph: string | undefined;
4
+ import { type DatasetCliOptions, type LoadedProjectRuntime, type ProviderCliOptions } from '../cliRuntime.js';
5
+ import { type HttpCliOptions } from '../http.js';
6
+ export type ServeArgs = {
8
7
  allowSpecifyingGraphId: boolean;
9
- openaiApiKey: string | undefined;
10
- openaiEndpoint: string | undefined;
11
- openaiOrganization: string | undefined;
8
+ dev: boolean;
9
+ endpoint: string[];
12
10
  exposeCost: boolean;
11
+ graph: string | undefined;
12
+ host: string;
13
+ port: number;
14
+ projectFile: string | undefined;
13
15
  stream: string | undefined;
14
16
  streamNode: string | undefined;
15
- };
17
+ unwrapOutput: string | undefined;
18
+ } & DatasetCliOptions & ProviderCliOptions & HttpCliOptions;
16
19
  type GraphRunArgs = {
17
20
  exposeCost: boolean;
18
21
  graph: string | undefined;
19
22
  inputs: Record<string, LooseDataValue>;
20
- openaiApiKey: string | undefined;
21
- openaiEndpoint: string | undefined;
22
- openaiOrganization: string | undefined;
23
23
  project: Project;
24
+ providerOptions: ProviderCliOptions;
25
+ runtime: Pick<LoadedProjectRuntime, 'datasetProvider' | 'projectPath'>;
26
+ unwrapOutput: string | undefined;
27
+ };
28
+ type GraphProcessorArgs = Omit<GraphRunArgs, 'exposeCost' | 'project' | 'providerOptions' | 'runtime' | 'unwrapOutput'> & ProviderCliOptions;
29
+ export type ServeAppInfo = {
30
+ app: Hono;
31
+ projectFilePath: string;
32
+ servedGraphName: string;
24
33
  };
25
- type GraphProcessorArgs = Omit<GraphRunArgs, 'exposeCost' | 'project'>;
26
34
  export declare function makeCommand<T>(y: yargs.Argv<T>): yargs.Argv<T & {
27
35
  port: number;
36
+ } & {
37
+ host: string;
28
38
  } & {
29
39
  dev: boolean;
30
40
  } & {
@@ -32,13 +42,11 @@ export declare function makeCommand<T>(y: yargs.Argv<T>): yargs.Argv<T & {
32
42
  } & {
33
43
  "allow-specifying-graph-id": boolean;
34
44
  } & {
35
- "openai-api-key": string | undefined;
36
- } & {
37
- "openai-endpoint": string | undefined;
38
- } & {
39
- "openai-organization": string | undefined;
45
+ endpoint: string[] | never[];
40
46
  } & {
41
47
  "expose-cost": boolean;
48
+ } & {
49
+ "unwrap-output": string | undefined;
42
50
  } & {
43
51
  stream: string | undefined;
44
52
  } & {
@@ -47,7 +55,9 @@ export declare function makeCommand<T>(y: yargs.Argv<T>): yargs.Argv<T & {
47
55
  projectFile: string | undefined;
48
56
  }>;
49
57
  export declare function serve(args: ServeArgs): Promise<void>;
58
+ export declare function createServeApp(args: ServeArgs): Promise<ServeAppInfo>;
50
59
  export declare function buildGraphProcessorOptions({ inputs, graph, openaiApiKey, openaiEndpoint, openaiOrganization, }: GraphProcessorArgs): NodeCreateProcessorOptions;
51
60
  export declare function buildStreamingGraphProcessorOptions(args: GraphProcessorArgs): NodeCreateProcessorOptions;
52
61
  export declare function buildStreamEventFilter(stream: string | undefined): RivetEventStreamFilterSpec;
62
+ export declare function parseEndpointAliases(endpointSpecs: string[], project: Project): Map<string, string>;
53
63
  export {};
@@ -0,0 +1,35 @@
1
+ import { Hono } from 'hono';
2
+ import type * as yargs from 'yargs';
3
+ import { type DatasetCliOptions, type ProviderCliOptions } from '../cliRuntime.js';
4
+ import { type HttpCliOptions } from '../http.js';
5
+ export type ServeAppArgs = {
6
+ basePath: string;
7
+ dev: boolean;
8
+ host: string;
9
+ port: number;
10
+ projectFile: string;
11
+ revisionKey: string | undefined;
12
+ uiGraph: string | undefined;
13
+ } & DatasetCliOptions & ProviderCliOptions & HttpCliOptions;
14
+ export type WebAppServeInfo = {
15
+ app: Hono;
16
+ projectFilePath: string;
17
+ uiGraphName: string;
18
+ };
19
+ export declare function makeCommand<T>(y: yargs.Argv<T>): yargs.Argv<T & {
20
+ projectFile: string;
21
+ } & {
22
+ uiGraph: string | undefined;
23
+ } & {
24
+ port: number;
25
+ } & {
26
+ host: string;
27
+ } & {
28
+ "base-path": string;
29
+ } & {
30
+ dev: boolean;
31
+ } & {
32
+ "revision-key": string | undefined;
33
+ }>;
34
+ export declare function serveApp(args: ServeAppArgs): Promise<void>;
35
+ export declare function createWebAppServeApp(args: ServeAppArgs): Promise<WebAppServeInfo>;
@@ -0,0 +1,23 @@
1
+ import type { Context, Hono, MiddlewareHandler } from 'hono';
2
+ import type * as yargs from 'yargs';
3
+ export type HttpCliOptions = {
4
+ bearerToken?: string;
5
+ corsOrigin?: string[];
6
+ };
7
+ export type HttpJsonError = {
8
+ error: {
9
+ message: string;
10
+ name: string;
11
+ };
12
+ durationMs: number;
13
+ };
14
+ export declare class CliHttpError extends Error {
15
+ readonly status: number;
16
+ constructor(message: string, status?: number);
17
+ }
18
+ export declare function addHttpOptions<T>(y: yargs.Argv<T>): yargs.Argv<T>;
19
+ export declare function createHttpMiddleware({ bearerToken, corsOrigin }: HttpCliOptions): MiddlewareHandler;
20
+ export declare function jsonErrorResponse(c: Context, error: unknown, startedAt: number, fallbackStatus?: number): Response;
21
+ export declare function jsonTimedResponse(c: Context, payload: unknown, startedAt: number): Response;
22
+ export declare function formatListenUrl(host: string, port: number): string;
23
+ export declare function startHttpServer(app: Hono, host: string, port: number): void;
@@ -0,0 +1,9 @@
1
+ import type { Outputs } from '@valerypopoff/rivet2-node';
2
+ export type OutputShapeOptions = {
3
+ includeCost?: boolean;
4
+ outputKey?: string;
5
+ unwrapOutput?: string;
6
+ };
7
+ export declare function shapeOutputs(outputs: Outputs, options: OutputShapeOptions): unknown;
8
+ export declare function validateOutputShapeOptions({ outputKey, unwrapOutput }: OutputShapeOptions): void;
9
+ export declare function writeJsonOutput(payload: unknown, outputFile: string | undefined): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@valerypopoff/rivet2-cli",
3
- "version": "2.0.11",
3
+ "version": "2.1.0",
4
4
  "license": "MIT",
5
5
  "types": "dist/types/cli.d.ts",
6
6
  "type": "module",
@@ -24,7 +24,7 @@
24
24
  "dependencies": {
25
25
  "@hono/node-server": "^1.13.8",
26
26
  "@types/dotenv": "^8.2.3",
27
- "@valerypopoff/rivet2-node": "^2.0.11",
27
+ "@valerypopoff/rivet2-node": "^2.1.0",
28
28
  "chalk": "^5.4.1",
29
29
  "didyoumean2": "^7.0.4",
30
30
  "dotenv": "^16.4.7",