Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lint and add lint + prettier to CI #461

Merged
merged 7 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
es2021: true,
},
root: true,
extends: ['standard-with-typescript', 'plugin:react/recommended'],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This plugin only appears to be used in app, so configuring it here seems to be a mistake

extends: ['standard-with-typescript'],
plugins: ['import', '@typescript-eslint'],
overrides: [
{
Expand Down Expand Up @@ -52,7 +52,8 @@ module.exports = {
'prefer-const': 'error',
'eol-last': 'off',
'import/no-duplicates': 'error',
'import/no-cycle': 'error',
// TODO: Enable after fixing cycle in CallGraphNode -> globalRivetNodeRegistry
'import/no-cycle': 'warn',
'no-extra-boolean-cast': 'off',
'no-prototype-builtins': 'off',
'no-undef-init': 'off',
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ jobs:
NODE_OPTIONS: --max_old_space_size=6000
- name: Test
run: yarn test
- name: Lint
run: yarn lint
- name: Prettier
run: yarn prettier --check
38 changes: 2 additions & 36 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion packages/app/src/components/Port.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ export const Port: FC<{
>
{canDragTo && <div className={clsx('port-hover-area')} />}
</div>
<div className={clsx("port-label", preservePortCase ? "" : "port-label-uppercase")} onMouseOver={handleMouseOver} onMouseOut={handleMouseOut}>
<div
className={clsx('port-label', preservePortCase ? '' : 'port-label-uppercase')}
onMouseOver={handleMouseOver}
onMouseOut={handleMouseOut}
>
{title}
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
{
files: ['*.ts', '*.tsx'],
parserOptions: {
project: './packages/cli/tsconfig.json',
project: './tsconfig.json',
ecmaVersion: 'latest',
sourceType: 'module',
},
Expand Down
189 changes: 99 additions & 90 deletions packages/cli/bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,99 +3,108 @@ import { resolve } from 'node:path';
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
await yargs(hideBin(process.argv))
.command('run <projectFile> [graphName]', 'Run a graph in a project file, or the main graph if graphName is not specified.', (y) => y
.positional('projectFile', {
describe: 'The project file to run',
type: 'string',
demandOption: true,
})
.positional('graphName', {
describe: 'The name of the graph to run',
type: 'string',
})
.option('inputs-stdin', {
describe: 'Read inputs from stdin as JSON',
type: 'boolean',
default: false,
})
.option('include-cost', {
describe: 'Include the total cost in the output',
type: 'boolean',
default: false,
})
.option('context', {
describe: 'Adds a context value to the graph run',
type: 'string',
array: true,
default: [],
})
.option('input', {
describe: 'Adds an input to the graph run',
type: 'string',
array: true,
default: [],
}), (args) => run(args))
.demandCommand()
.parseAsync();
.command(
'run <projectFile> [graphName]',
'Run a graph in a project file, or the main graph if graphName is not specified.',
(y) =>
y
.positional('projectFile', {
describe: 'The project file to run',
type: 'string',
demandOption: true,
})
.positional('graphName', {
describe: 'The name of the graph to run',
type: 'string',
})
.option('inputs-stdin', {
describe: 'Read inputs from stdin as JSON',
type: 'boolean',
default: false,
})
.option('include-cost', {
describe: 'Include the total cost in the output',
type: 'boolean',
default: false,
})
.option('context', {
describe: 'Adds a context value to the graph run',
type: 'string',
array: true,
default: [],
})
.option('input', {
describe: 'Adds an input to the graph run',
type: 'string',
array: true,
default: [],
}),
(args) => run(args),
)
.demandCommand()
.parseAsync();
async function run(args) {
try {
const projectPath = resolve(process.cwd(), args.projectFile);
const project = await loadProjectFromFile(projectPath);
if (!args.graphName && !project.metadata.mainGraphId) {
const validGraphs = Object.values(project.graphs).map((graph) => [graph.metadata.id, graph.metadata.name]);
const validGraphNames = validGraphs.map(([id, name]) => `• "${name}" (${id})`);
console.error(`No graph name provided, and project does not specify a main graph. Valid graphs are: \n${validGraphNames.join('\n')}\n\n Use either the graph's name or its ID. For example, \`rivet run my-project.rivet-project my-graph\` or \`rivet run my-project.rivet-project 1234abcd\``);
process.exit(1);
}
let inputs = {};
if (args.inputsStdin) {
// Read json from stdin
const stdin = process.stdin;
stdin.setEncoding('utf8');
let input = '';
for await (const chunk of stdin) {
input += chunk;
}
try {
inputs = JSON.parse(input);
}
catch (err) {
console.error('Failed to parse input JSON');
console.error(err);
process.exit(1);
}
}
else {
inputs = Object.fromEntries(args.input.map((input) => {
const [key, value] = input.split('=');
if (!key || !value) {
console.error(`Invalid input value: ${input}`);
process.exit(1);
}
return [key, value];
}));
}
const contextValues = Object.fromEntries(args.context.map((context) => {
const [key, value] = context.split('=');
if (!key || !value) {
console.error(`Invalid context value: ${context}`);
process.exit(1);
}
return [key, value];
}));
const { run } = createProcessor(project, {
graph: args.graphName,
inputs,
context: contextValues,
});
const outputs = await run();
if (!args.includeCost) {
delete outputs.cost;
}
console.log(outputs);
try {
const projectPath = resolve(process.cwd(), args.projectFile);
const project = await loadProjectFromFile(projectPath);
if (!args.graphName && !project.metadata.mainGraphId) {
const validGraphs = Object.values(project.graphs).map((graph) => [graph.metadata.id, graph.metadata.name]);
const validGraphNames = validGraphs.map(([id, name]) => `• "${name}" (${id})`);
console.error(
`No graph name provided, and project does not specify a main graph. Valid graphs are: \n${validGraphNames.join('\n')}\n\n Use either the graph's name or its ID. For example, \`rivet run my-project.rivet-project my-graph\` or \`rivet run my-project.rivet-project 1234abcd\``,
);
process.exit(1);
}
catch (err) {
let inputs = {};
if (args.inputsStdin) {
// Read json from stdin
const stdin = process.stdin;
stdin.setEncoding('utf8');
let input = '';
for await (const chunk of stdin) {
input += chunk;
}
try {
inputs = JSON.parse(input);
} catch (err) {
console.error('Failed to parse input JSON');
console.error(err);
process.exit(1);
}
} else {
inputs = Object.fromEntries(
args.input.map((input) => {
const [key, value] = input.split('=');
if (!key || !value) {
console.error(`Invalid input value: ${input}`);
process.exit(1);
}
return [key, value];
}),
);
}
const contextValues = Object.fromEntries(
args.context.map((context) => {
const [key, value] = context.split('=');
if (!key || !value) {
console.error(`Invalid context value: ${context}`);
process.exit(1);
}
return [key, value];
}),
);
const { run } = createProcessor(project, {
graph: args.graphName,
inputs,
context: contextValues,
});
const outputs = await run();
if (!args.includeCost) {
delete outputs.cost;
}
console.log(outputs);
} catch (err) {
console.error(err);
process.exit(1);
}
}
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
},
"devDependencies": {
"@types/yargs": "^17.0.29",
"@typescript-eslint/eslint-plugin": "^6.9.0",
"eslint": "^8.52.0",
"eslint-config-standard-with-typescript": "^39.1.1",
"eslint-plugin-import": "^2.29.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { type Settings } from '../../index.js';
import { type EmbeddingGenerator } from '../EmbeddingGenerator.js';
import { OpenAI } from 'openai';

type OpenAIOptions = Pick<OpenAI.EmbeddingCreateParams, 'model' | 'dimensions' >
type OpenAIOptions = Pick<OpenAI.EmbeddingCreateParams, 'model' | 'dimensions'>;

export class OpenAIEmbeddingGenerator implements EmbeddingGenerator {
readonly #settings;
Expand All @@ -21,7 +21,7 @@ export class OpenAIEmbeddingGenerator implements EmbeddingGenerator {
const response = await api.embeddings.create({
input: text,
model: options?.model ?? 'text-embedding-ada-002',
dimensions: options?.dimensions
dimensions: options?.dimensions,
});

const embeddings = response.data;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/model/GraphProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import { P, match } from 'ts-pattern';
import type { Opaque } from 'type-fest';
import { coerceTypeOptional } from '../utils/coerceType.js';
import { globalRivetNodeRegistry } from './Nodes.js';

Check warning on line 36 in packages/core/src/model/GraphProcessor.ts

View workflow job for this annotation

GitHub Actions / build

Dependency cycle via ./nodes/CallGraphNode.js:210=>../../api/createProcessor.js:15

Check warning on line 36 in packages/core/src/model/GraphProcessor.ts

View workflow job for this annotation

GitHub Actions / build

Dependency cycle via ./nodes/CallGraphNode.js:210=>../../api/createProcessor.js:15
import type { BuiltInNodeType, BuiltInNodes } from './Nodes.js';
import type { NodeRegistration } from './NodeRegistration.js';
import { getPluginConfig } from '../utils/index.js';
Expand Down Expand Up @@ -919,7 +919,7 @@
if (this.runToNodeIds) {
const dependencyNodes = this.getDependencyNodesDeep(node.id);

if (this.runToNodeIds.some((runTo) => runTo != node.id && dependencyNodes.includes(runTo))) {
if (this.runToNodeIds.some((runTo) => runTo !== node.id && dependencyNodes.includes(runTo))) {
this.#emitter.emit('trace', `Node ${node.title} is excluded due to runToNodeIds`);
return;
}
Expand Down
4 changes: 0 additions & 4 deletions packages/core/src/model/Nodes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import type { ChartNode } from './NodeBase.js';
import { NodeRegistration } from './NodeRegistration.js';
import type { NodeImpl } from './NodeImpl.js';

import { userInputNode } from './nodes/UserInputNode.js';
export * from './nodes/UserInputNode.js';
Expand Down Expand Up @@ -209,7 +207,7 @@
import { graphReferenceNode } from './nodes/GraphReferenceNode.js';
export * from './nodes/GraphReferenceNode.js';

import { callGraphNode } from './nodes/CallGraphNode.js';

Check warning on line 210 in packages/core/src/model/Nodes.ts

View workflow job for this annotation

GitHub Actions / build

Dependency cycle via ../../api/createProcessor.js:15=>../model/GraphProcessor.js:19

Check warning on line 210 in packages/core/src/model/Nodes.ts

View workflow job for this annotation

GitHub Actions / build

Dependency cycle via ../../api/createProcessor.js:15=>../model/GraphProcessor.js:19
export * from './nodes/CallGraphNode.js';

import { delegateFunctionCallNode } from './nodes/DelegateFunctionCallNode.js';
Expand All @@ -218,8 +216,6 @@
import { playAudioNode } from './nodes/PlayAudioNode.js';
export * from './nodes/PlayAudioNode.js';

export * from './nodes/CallGraphNode.js';

export const registerBuiltInNodes = (registry: NodeRegistration) => {
return registry
.register(toYamlNode)
Expand Down
7 changes: 3 additions & 4 deletions packages/core/src/model/nodes/CallGraphNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
import { NodeImpl, type NodeUIData } from '../NodeImpl.js';
import { nodeDefinition } from '../NodeDefinition.js';
import { type Inputs, type Outputs } from '../GraphProcessor.js';
import { type GraphId } from '../NodeGraph.js';
import { nanoid } from 'nanoid/non-secure';
import { type InternalProcessContext } from '../ProcessContext.js';
import { dedent } from 'ts-dedent';
import { coerceType, coerceTypeOptional } from '../../utils/coerceType.js';
import { looseDataValuesToDataValues, type LooseDataValue } from '../../index.js';
import { coerceTypeOptional } from '../../utils/coerceType.js';
import { looseDataValuesToDataValues, type LooseDataValue } from '../../api/createProcessor.js';

Check warning on line 15 in packages/core/src/model/nodes/CallGraphNode.ts

View workflow job for this annotation

GitHub Actions / build

Dependency cycle via ../model/GraphProcessor.js:19=>./Nodes.js:36

Check warning on line 15 in packages/core/src/model/nodes/CallGraphNode.ts

View workflow job for this annotation

GitHub Actions / build

Dependency cycle via ../model/GraphProcessor.js:19=>./Nodes.js:36
import { getError } from '../../utils/errors.js';

export type CallGraphNode = ChartNode<'callGraph', CallGraphNodeData>;
Expand Down Expand Up @@ -122,7 +121,7 @@

const subGraphProcessor = context.createSubProcessor(graphRef.graphId, { signal: context.signal });

let outputs: Outputs = {};
const outputs: Outputs = {};

try {
const startTime = Date.now();
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/model/nodes/ExtractJsonNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ export class ExtractJsonNodeImpl extends NodeImpl<ExtractJsonNode> {

// Find the first { or [ and the last } or ], and try parsing everything in between including them.

let firstBracket = inputString.indexOf('{');
let lastBracket = inputString.lastIndexOf('}');
let firstSquareBracket = inputString.indexOf('[');
let lastSquareBracket = inputString.lastIndexOf(']');
const firstBracket = inputString.indexOf('{');
const lastBracket = inputString.lastIndexOf('}');
const firstSquareBracket = inputString.indexOf('[');
const lastSquareBracket = inputString.lastIndexOf(']');

const firstIndex =
firstBracket >= 0 && firstSquareBracket >= 0
Expand Down
Loading
Loading