@alpic80/rivet-cli 1.24.2-aidon.15 → 1.24.2-aidon.17
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/bin/commands/serve.js +29 -20
- package/package.json +1 -1
package/bin/commands/serve.js
CHANGED
|
@@ -4,7 +4,7 @@ import { readdir, stat } from 'node:fs/promises';
|
|
|
4
4
|
import * as path from 'path';
|
|
5
5
|
import { extname, isAbsolute, join } from 'node:path';
|
|
6
6
|
import didYouMean from 'didyoumean2';
|
|
7
|
-
import { createProcessor, loadProjectFromFile, getSingleNodeStream, } from '@alpic80/rivet-node';
|
|
7
|
+
import { createProcessor, loadProjectFromFile, NodeDatasetProvider, getSingleNodeStream, } from '@alpic80/rivet-node';
|
|
8
8
|
import chalk from 'chalk';
|
|
9
9
|
import { configDotenv } from 'dotenv';
|
|
10
10
|
import * as Rivet from '@ironclad/rivet-node';
|
|
@@ -107,7 +107,6 @@ const conditionalLogger = () => {
|
|
|
107
107
|
export async function serve(cliArgs = {}) {
|
|
108
108
|
try {
|
|
109
109
|
configDotenv();
|
|
110
|
-
debugger;
|
|
111
110
|
const pluginSettings = await setupPlugins(Rivet);
|
|
112
111
|
const args = {
|
|
113
112
|
hostname: cliArgs.hostname ?? process.env.SERVE_HOSTNAME ?? '127.0.0.1',
|
|
@@ -115,15 +114,15 @@ export async function serve(cliArgs = {}) {
|
|
|
115
114
|
projectFile: cliArgs.projectFile ?? process.env.PROJECT_FILE,
|
|
116
115
|
dev: cliArgs.dev ?? process.env.NODE_ENV === 'development',
|
|
117
116
|
graph: cliArgs.graph ?? process.env.GRAPH,
|
|
118
|
-
allowSpecifyingGraphId: cliArgs.allowSpecifyingGraphId
|
|
117
|
+
allowSpecifyingGraphId: 'allowSpecifyingGraphId' in cliArgs ? cliArgs.allowSpecifyingGraphId : (process.env.ALLOW_SPECIFYING_GRAPH_ID === 'true'),
|
|
119
118
|
openaiApiKey: cliArgs.openaiApiKey ?? process.env.OPENAI_API_KEY,
|
|
120
119
|
openaiEndpoint: cliArgs.openaiEndpoint ?? process.env.OPENAI_ENDPOINT,
|
|
121
120
|
openaiOrganization: cliArgs.openaiOrganization ?? process.env.OPENAI_ORGANIZATION,
|
|
122
|
-
exposeCost: cliArgs.exposeCost
|
|
123
|
-
exposeUsage: cliArgs.exposeUsage
|
|
124
|
-
logRequests: cliArgs.logRequests
|
|
125
|
-
logActivity: cliArgs.logActivity
|
|
126
|
-
logTrace: cliArgs.logTrace
|
|
121
|
+
exposeCost: 'exposeCost' in cliArgs ? cliArgs.exposeCost : (process.env.EXPOSE_COST === 'true'),
|
|
122
|
+
exposeUsage: 'exposeUsage' in cliArgs ? cliArgs.exposeUsage : (process.env.EXPOSE_USAGE === 'true'),
|
|
123
|
+
logRequests: 'logRequests' in cliArgs ? cliArgs.logRequests : (process.env.LOG_REQUESTS === 'true'),
|
|
124
|
+
logActivity: 'logActivity' in cliArgs ? cliArgs.logActivity : (process.env.LOG_ACTIVITY === 'true'),
|
|
125
|
+
logTrace: 'logTrace' in cliArgs ? cliArgs.logTrace : (process.env.LOG_TRACE === 'true'),
|
|
127
126
|
stream: cliArgs.stream ?? process.env.STREAM,
|
|
128
127
|
streamNode: cliArgs.streamNode ?? process.env.STREAM_NODE,
|
|
129
128
|
events: cliArgs.events ?? process.env.EVENTS,
|
|
@@ -135,7 +134,7 @@ export async function serve(cliArgs = {}) {
|
|
|
135
134
|
if (args.logRequests) {
|
|
136
135
|
app.use('*', conditionalLogger());
|
|
137
136
|
}
|
|
138
|
-
let
|
|
137
|
+
let projectPath = '';
|
|
139
138
|
let initialProject = null;
|
|
140
139
|
if (args.projectsRootDir) {
|
|
141
140
|
if (!(await validateProjectRootDirectory(args.projectsRootDir))) {
|
|
@@ -143,9 +142,9 @@ export async function serve(cliArgs = {}) {
|
|
|
143
142
|
}
|
|
144
143
|
}
|
|
145
144
|
else {
|
|
146
|
-
|
|
147
|
-
initialProject = await loadProjectFromFile(
|
|
148
|
-
throwIfNoMainGraph(initialProject, args.graph,
|
|
145
|
+
projectPath = await getProjectFile(args.projectFile);
|
|
146
|
+
initialProject = await loadProjectFromFile(projectPath);
|
|
147
|
+
throwIfNoMainGraph(initialProject, args.graph, projectPath);
|
|
149
148
|
throwIfInvalidGraph(initialProject, args.graph);
|
|
150
149
|
}
|
|
151
150
|
console.log(chalk.green('Server running version 11'));
|
|
@@ -176,9 +175,9 @@ export async function serve(cliArgs = {}) {
|
|
|
176
175
|
c.req.raw.headers.forEach((value, key) => {
|
|
177
176
|
headers[key] = value;
|
|
178
177
|
});
|
|
179
|
-
const project = args.dev ? await loadProjectFromFile(
|
|
178
|
+
const project = args.dev ? await loadProjectFromFile(projectPath) : initialProject;
|
|
180
179
|
const inputText = await c.req.text();
|
|
181
|
-
return await processGraph({ project, headers, inputText });
|
|
180
|
+
return await processGraph({ project, projectPath, headers, inputText });
|
|
182
181
|
});
|
|
183
182
|
if (args.allowSpecifyingGraphId || args.projectsRootDir) {
|
|
184
183
|
app.post('/*', async (c) => {
|
|
@@ -205,6 +204,7 @@ export async function serve(cliArgs = {}) {
|
|
|
205
204
|
graphFile = parts.join('/');
|
|
206
205
|
}
|
|
207
206
|
let project;
|
|
207
|
+
let projectPath = '';
|
|
208
208
|
if (args.projectsRootDir) {
|
|
209
209
|
if (!graphFile) {
|
|
210
210
|
if (args.logActivity) {
|
|
@@ -219,13 +219,14 @@ export async function serve(cliArgs = {}) {
|
|
|
219
219
|
}
|
|
220
220
|
return c.text(`GraphFile ${graphFile} not found in root directory (${args.projectsRootDir})`, 400);
|
|
221
221
|
}
|
|
222
|
-
|
|
222
|
+
projectPath = path.join(args.projectsRootDir, graphFile);
|
|
223
|
+
project = await loadProjectFromFile(projectPath);
|
|
223
224
|
}
|
|
224
225
|
else {
|
|
225
|
-
project = args.dev || args.projectsRootDir ? await loadProjectFromFile(
|
|
226
|
+
project = args.dev || args.projectsRootDir ? await loadProjectFromFile(projectPath) : initialProject;
|
|
226
227
|
}
|
|
227
228
|
const inputText = await c.req.text();
|
|
228
|
-
return await processGraph({ project, headers, inputText, graphId });
|
|
229
|
+
return await processGraph({ project, projectPath, headers, inputText, graphId });
|
|
229
230
|
});
|
|
230
231
|
}
|
|
231
232
|
const server = serveHono({
|
|
@@ -246,7 +247,7 @@ export async function serve(cliArgs = {}) {
|
|
|
246
247
|
const graph = Object.values(initialProject.graphs).find((g) => g.metadata.id === initialProject.metadata.mainGraphId);
|
|
247
248
|
servedGraphName = graph.metadata.name;
|
|
248
249
|
}
|
|
249
|
-
console.log(chalk.green(`Serving project file ${chalk.bold.white(
|
|
250
|
+
console.log(chalk.green(`Serving project file ${chalk.bold.white(projectPath)} on port ${chalk.bold.white(args.port)}.\nServing graph "${chalk.bold.white(servedGraphName)}".`));
|
|
250
251
|
}
|
|
251
252
|
else {
|
|
252
253
|
console.log(chalk.red(`Misconfiguration, not serving from directory and have no initialProject`));
|
|
@@ -355,11 +356,15 @@ const parseStream = (stream) => {
|
|
|
355
356
|
}
|
|
356
357
|
return { start, finish, delta };
|
|
357
358
|
};
|
|
358
|
-
async function streamGraph({ project, inputs, graphId, pluginSettings, openaiApiKey, openaiEndpoint, openaiOrganization, exposeCost, exposeUsage, logActivity, logTrace, stream, streamNode, events }) {
|
|
359
|
+
async function streamGraph({ project, projectPath, inputs, graphId, pluginSettings, openaiApiKey, openaiEndpoint, openaiOrganization, exposeCost, exposeUsage, logActivity, logTrace, stream, streamNode, events }) {
|
|
360
|
+
const NDSOptions = { save: true };
|
|
361
|
+
const datasetProvider = await NodeDatasetProvider.fromProjectFile(projectPath, NDSOptions);
|
|
359
362
|
const { run, processor, getSSEStream } = createProcessor(project, {
|
|
360
363
|
inputs,
|
|
361
364
|
graph: graphId,
|
|
362
365
|
pluginSettings,
|
|
366
|
+
projectPath,
|
|
367
|
+
datasetProvider,
|
|
363
368
|
openAiKey: openaiApiKey,
|
|
364
369
|
openAiEndpoint: openaiEndpoint,
|
|
365
370
|
openAiOrganization: openaiOrganization,
|
|
@@ -415,11 +420,15 @@ async function streamGraph({ project, inputs, graphId, pluginSettings, openaiApi
|
|
|
415
420
|
return sseStream;
|
|
416
421
|
}
|
|
417
422
|
}
|
|
418
|
-
async function runGraph({ project, inputs, graphId, pluginSettings, openaiApiKey, openaiEndpoint, openaiOrganization, exposeCost, exposeUsage, logTrace }) {
|
|
423
|
+
async function runGraph({ project, projectPath, inputs, graphId, pluginSettings, openaiApiKey, openaiEndpoint, openaiOrganization, exposeCost, exposeUsage, logTrace }) {
|
|
424
|
+
const NDSOptions = { save: true };
|
|
425
|
+
const datasetProvider = await NodeDatasetProvider.fromProjectFile(projectPath, NDSOptions);
|
|
419
426
|
const { run } = createProcessor(project, {
|
|
420
427
|
inputs,
|
|
421
428
|
graph: graphId,
|
|
422
429
|
pluginSettings,
|
|
430
|
+
projectPath,
|
|
431
|
+
datasetProvider,
|
|
423
432
|
openAiKey: openaiApiKey,
|
|
424
433
|
openAiEndpoint: openaiEndpoint,
|
|
425
434
|
openAiOrganization: openaiOrganization,
|