@alpic80/rivet-cli 1.24.2-aidon.16 → 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 +23 -13
- 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';
|
|
@@ -134,7 +134,7 @@ export async function serve(cliArgs = {}) {
|
|
|
134
134
|
if (args.logRequests) {
|
|
135
135
|
app.use('*', conditionalLogger());
|
|
136
136
|
}
|
|
137
|
-
let
|
|
137
|
+
let projectPath = '';
|
|
138
138
|
let initialProject = null;
|
|
139
139
|
if (args.projectsRootDir) {
|
|
140
140
|
if (!(await validateProjectRootDirectory(args.projectsRootDir))) {
|
|
@@ -142,9 +142,9 @@ export async function serve(cliArgs = {}) {
|
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
144
|
else {
|
|
145
|
-
|
|
146
|
-
initialProject = await loadProjectFromFile(
|
|
147
|
-
throwIfNoMainGraph(initialProject, args.graph,
|
|
145
|
+
projectPath = await getProjectFile(args.projectFile);
|
|
146
|
+
initialProject = await loadProjectFromFile(projectPath);
|
|
147
|
+
throwIfNoMainGraph(initialProject, args.graph, projectPath);
|
|
148
148
|
throwIfInvalidGraph(initialProject, args.graph);
|
|
149
149
|
}
|
|
150
150
|
console.log(chalk.green('Server running version 11'));
|
|
@@ -175,9 +175,9 @@ export async function serve(cliArgs = {}) {
|
|
|
175
175
|
c.req.raw.headers.forEach((value, key) => {
|
|
176
176
|
headers[key] = value;
|
|
177
177
|
});
|
|
178
|
-
const project = args.dev ? await loadProjectFromFile(
|
|
178
|
+
const project = args.dev ? await loadProjectFromFile(projectPath) : initialProject;
|
|
179
179
|
const inputText = await c.req.text();
|
|
180
|
-
return await processGraph({ project, headers, inputText });
|
|
180
|
+
return await processGraph({ project, projectPath, headers, inputText });
|
|
181
181
|
});
|
|
182
182
|
if (args.allowSpecifyingGraphId || args.projectsRootDir) {
|
|
183
183
|
app.post('/*', async (c) => {
|
|
@@ -204,6 +204,7 @@ export async function serve(cliArgs = {}) {
|
|
|
204
204
|
graphFile = parts.join('/');
|
|
205
205
|
}
|
|
206
206
|
let project;
|
|
207
|
+
let projectPath = '';
|
|
207
208
|
if (args.projectsRootDir) {
|
|
208
209
|
if (!graphFile) {
|
|
209
210
|
if (args.logActivity) {
|
|
@@ -218,13 +219,14 @@ export async function serve(cliArgs = {}) {
|
|
|
218
219
|
}
|
|
219
220
|
return c.text(`GraphFile ${graphFile} not found in root directory (${args.projectsRootDir})`, 400);
|
|
220
221
|
}
|
|
221
|
-
|
|
222
|
+
projectPath = path.join(args.projectsRootDir, graphFile);
|
|
223
|
+
project = await loadProjectFromFile(projectPath);
|
|
222
224
|
}
|
|
223
225
|
else {
|
|
224
|
-
project = args.dev || args.projectsRootDir ? await loadProjectFromFile(
|
|
226
|
+
project = args.dev || args.projectsRootDir ? await loadProjectFromFile(projectPath) : initialProject;
|
|
225
227
|
}
|
|
226
228
|
const inputText = await c.req.text();
|
|
227
|
-
return await processGraph({ project, headers, inputText, graphId });
|
|
229
|
+
return await processGraph({ project, projectPath, headers, inputText, graphId });
|
|
228
230
|
});
|
|
229
231
|
}
|
|
230
232
|
const server = serveHono({
|
|
@@ -245,7 +247,7 @@ export async function serve(cliArgs = {}) {
|
|
|
245
247
|
const graph = Object.values(initialProject.graphs).find((g) => g.metadata.id === initialProject.metadata.mainGraphId);
|
|
246
248
|
servedGraphName = graph.metadata.name;
|
|
247
249
|
}
|
|
248
|
-
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)}".`));
|
|
249
251
|
}
|
|
250
252
|
else {
|
|
251
253
|
console.log(chalk.red(`Misconfiguration, not serving from directory and have no initialProject`));
|
|
@@ -354,11 +356,15 @@ const parseStream = (stream) => {
|
|
|
354
356
|
}
|
|
355
357
|
return { start, finish, delta };
|
|
356
358
|
};
|
|
357
|
-
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);
|
|
358
362
|
const { run, processor, getSSEStream } = createProcessor(project, {
|
|
359
363
|
inputs,
|
|
360
364
|
graph: graphId,
|
|
361
365
|
pluginSettings,
|
|
366
|
+
projectPath,
|
|
367
|
+
datasetProvider,
|
|
362
368
|
openAiKey: openaiApiKey,
|
|
363
369
|
openAiEndpoint: openaiEndpoint,
|
|
364
370
|
openAiOrganization: openaiOrganization,
|
|
@@ -414,11 +420,15 @@ async function streamGraph({ project, inputs, graphId, pluginSettings, openaiApi
|
|
|
414
420
|
return sseStream;
|
|
415
421
|
}
|
|
416
422
|
}
|
|
417
|
-
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);
|
|
418
426
|
const { run } = createProcessor(project, {
|
|
419
427
|
inputs,
|
|
420
428
|
graph: graphId,
|
|
421
429
|
pluginSettings,
|
|
430
|
+
projectPath,
|
|
431
|
+
datasetProvider,
|
|
422
432
|
openAiKey: openaiApiKey,
|
|
423
433
|
openAiEndpoint: openaiEndpoint,
|
|
424
434
|
openAiOrganization: openaiOrganization,
|