Skip to content

Commit

Permalink
fix: cli example
Browse files Browse the repository at this point in the history
  • Loading branch information
sroussey committed Mar 3, 2025
1 parent a64d1b5 commit 028af70
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion examples/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"watch": "concurrently -c 'auto' -n 'cli:' 'bun:watch-*'",
"watch-js": "bun build --watch --target=bun --sourcemap=external --packages=external --outdir ./dist ./src/ellmers.ts",
"watch-types": "tsc --watch --preserveWatchOutput",
"build": "bun run build-clean && bun run build-js",
"build": "bun run build-clean && bun run build-js && bun run build-types",
"build-clean": "rm -fr dist/* tsconfig.tsbuildinfo",
"build-js": "bun build --target=bun --packages=external --outdir ./dist ./src/ellmers.ts",
"build-types": "tsc",
Expand Down
6 changes: 3 additions & 3 deletions examples/cli/src/TaskCLI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function AddBaseCommands(program: Command) {
if (options.model) {
const model = await getGlobalModelRepository().findByName(options.model);
if (model) {
graph.addTask(new DownloadModelTask({ input: { model: model.name } }));
graph.addTask(new DownloadModelTask({ model: model.name }));
} else {
program.error(`Unknown model ${options.model}`);
}
Expand Down Expand Up @@ -141,7 +141,7 @@ export function AddBaseCommands(program: Command) {
];
json = JSON.stringify(exampleJson);
}
const task = new JsonTask({ name: "JSON Task Example", input: { json } });
const task = new JsonTask({ json }, { name: "JSON Task Example" });
const graph = new TaskGraph();
graph.addTask(task);
try {
Expand All @@ -161,7 +161,7 @@ export function AddBaseCommands(program: Command) {
.TextEmbedding({
text: "The quick brown fox jumps over the lazy dog.",
})
.rename("vector", "message")
.rename("*", "messages")
.DebugLog();

try {
Expand Down
2 changes: 1 addition & 1 deletion examples/cli/src/TaskGraphToUI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { TaskGraph, TaskGraphRunner } from "@ellmers/task-graph";
import React from "react";
import { render } from "ink";
import { render } from "tuir";
import App from "./components/App";
import { sleep } from "@ellmers/util";

Expand Down
2 changes: 1 addition & 1 deletion examples/cli/src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const App: React.FC<AppProps> = ({ runner }) => {
<Box marginBottom={1}>
<Text bold>Ellmers Task Graph Runner</Text>
</Box>
<TaskGraphUI graph={runner.dag} />
<TaskGraphUI graph={runner.graph} />
</Box>
);
};
Expand Down
8 changes: 4 additions & 4 deletions examples/cli/src/components/TaskGraphUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@

import React, { useState, useEffect } from "react";
import { Box } from "tuir";
import { Task, TaskGraph } from "@ellmers/task-graph";
import { ITask, TaskGraph } from "@ellmers/task-graph";
import { TaskUI } from "./TaskUI";

type TaskGraphUIProps = {
graph: TaskGraph;
};

function findRootTasks(graph: TaskGraph): Task[] {
function findRootTasks(graph: TaskGraph): ITask[] {
return graph.getNodes().filter((task) => graph.getSourceTasks(task.config.id).length === 0);
}

const TaskGraphUI: React.FC<TaskGraphUIProps> = ({ graph }) => {
const [tasks, setTasks] = useState<Task[]>([]);
const [tasks, setTasks] = useState<ITask[]>([]);
const [status, setStatus] = useState<number>(0);

// Force a re-render
Expand All @@ -29,7 +29,7 @@ const TaskGraphUI: React.FC<TaskGraphUIProps> = ({ graph }) => {

// Set up event listeners for task status changes
useEffect(() => {
const setupTaskListeners = (currentTask: Task) => {
const setupTaskListeners = (currentTask: ITask) => {
// Set up listeners for this task
currentTask.on("regenerate", forceUpdate);
};
Expand Down
9 changes: 4 additions & 5 deletions packages/tasks/src/task/JsonTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from "@ellmers/task-graph";

interface JsonTaskInput extends TaskInput {
json?: string;
json: string;
}

interface JsonTaskOutput extends TaskOutput {
Expand Down Expand Up @@ -61,7 +61,7 @@ export class JsonTask<
* Creates a task instance from a JSON task item configuration
* Validates required fields and resolves task type from registry
*/
private createTask(item: JsonTaskItem) {
private createTaskFromJSON(item: JsonTaskItem) {
if (!item.id) throw new Error("Task id required");
if (!item.type) throw new Error("Task type required");
if (item.input && (Array.isArray(item.input) || Array.isArray(item.provenance)))
Expand All @@ -80,8 +80,7 @@ export class JsonTask<
name: item.name,
provenance: item.provenance ?? {},
};

const task = new taskClass({}, taskConfig);
const task = new taskClass(item.input ?? {}, taskConfig);
if (task.isCompound && item.subtasks) {
task.subGraph = this.createSubGraph(item.subtasks);
}
Expand All @@ -95,7 +94,7 @@ export class JsonTask<
private createSubGraph(jsonItems: JsonTaskItem[]) {
const subGraph = new TaskGraph();
for (const subitem of jsonItems) {
subGraph.addTask(this.createTask(subitem));
subGraph.addTask(this.createTaskFromJSON(subitem));
}
return subGraph;
}
Expand Down

0 comments on commit 028af70

Please sign in to comment.