Skip to content

Commit 197fc6d

Browse files
authored
feat: Task constructor signature, ToolCallingTask and AgentTask (#353)
* feat(ai): restore ToolCallingTask and AgentTask for development * refactor: simplify type handling by removing unnecessary casts * refactor(ai): apply TypeScript's override keyword across agent and tool task classes * refactor(ai): update timeout handling and enhance tool parsing functionality * refactor(logging): update testing logger initialization and configuration * refactor: enhance error handling and diagnostics across job queue and execution strategies * feat(ai-provider): introduce ToolCallParser and enhance tool calling functionality * feat(ai-provider): enhance tool call parsing and message handling * feat(ai-provider): implement shared streaming helper for text chunk generation * feat(ai-provider): enhance tool call parsing and message handling * feat(ai-provider): enhance logging and add integration tests for LlamaCpp models * refactor: change Task constructor to take only config, not input * refactor: update test files for new Task constructor signature * refactor: update remaining test files for new Task constructor * refactor: update TaskJSON test for new Task constructor * refactor: update all task/ test files for new Task constructor * fix: resolve remaining constructor signature issues * fix: fix LambdaTask helper and ArrayTask test constructor patterns * fix: fix ConditionalTask and TaskRunnerStreaming test constructor patterns * fix: fix ArrayTask inner task cloning to use new constructor signature * refactor: update task configurations to use new TaskConfig structure * refactor: update task configurations to use generic TaskConfig types
1 parent bba6010 commit 197fc6d

222 files changed

Lines changed: 9957 additions & 1635 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bunfig.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# Explicitly set the linker to isolated
33
linker = "isolated"
44
[test]
5-
retry = 1
5+
retry = 0
66
root = "./packages/test/src/test"
77
preload = ["./scripts/configure-hft-test-cache.ts"]
8+
[console]
9+
depth = 5

examples/cli/src/commands/agent.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
computeGraphInputSchema,
99
createGraphFromGraphJSON,
1010
type TaskGraphJson,
11+
type TaskDeserializationOptions,
1112
} from "@workglow/task-graph";
1213
import type { DataPortSchemaObject } from "@workglow/util/schema";
1314
import type { Command } from "commander";
@@ -233,9 +234,24 @@ export function registerAgentCommand(program: Command): void {
233234
process.exit(1);
234235
}
235236

237+
// Restrict which task types can be instantiated from untrusted agent JSON.
238+
// This allowlist should include only task types that are safe and expected in agent graphs.
239+
const deserializationOptions: TaskDeserializationOptions = {
240+
allowedTypes: new Set<string>([
241+
// Core control-flow / composition tasks
242+
"GraphAsTask",
243+
"ConditionalTask",
244+
"IteratorTask",
245+
"MapTask",
246+
"ReduceTask",
247+
"WhileTask",
248+
// Add additional allowed task type names here as needed.
249+
]),
250+
};
251+
236252
let graph;
237253
try {
238-
graph = createGraphFromGraphJSON(json);
254+
graph = createGraphFromGraphJSON(json, undefined, deserializationOptions);
239255
} catch (e) {
240256
console.error(`Invalid agent graph: ${formatError(e)}`);
241257
process.exit(1);

examples/web/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ export const App = () => {
218218

219219
const setNewJson = useCallback(
220220
(json: string) => {
221-
const task = new JsonTask({ json });
221+
const task = new JsonTask({ defaults: { json } });
222222
if (task.hasChildren()) {
223223
workflow.graph = task.subGraph;
224224
} else {

examples/web/src/editor/JsonEditor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const JsonEditor: React.FC<PopupProps> = ({
4040
// this will throw an error if the JSON is invalid
4141
JSON.parse(jsonString);
4242
// this will throw an error if the JSON is not a valid task graph
43-
new JsonTask({ json: jsonString }, { title: "Test JSON" });
43+
new JsonTask({ title: "Test JSON", defaults: { json: jsonString } });
4444

4545
setIsValidJSON(true);
4646
setCode(jsonString);

packages/ai-provider/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
"test": "bun test"
2121
},
2222
"exports": {
23-
"./src/*": "./src/*",
23+
"./test": {
24+
"types": "./src/common/ToolCallParsers.ts",
25+
"import": "./src/common/ToolCallParsers.ts"
26+
},
2427
"./anthropic": {
2528
"types": "./dist/provider-anthropic/index.d.ts",
2629
"import": "./dist/provider-anthropic/index.js"
@@ -213,4 +216,4 @@
213216
"tiktoken": "catalog:",
214217
"js-tiktoken": "catalog:"
215218
}
216-
}
219+
}

0 commit comments

Comments
 (0)