Skip to content
Draft
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
3 changes: 3 additions & 0 deletions agent-service/LICENSE-binary
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ Agent service npm packages:
- @ai-sdk/openai@4.0.118
- @ai-sdk/provider-utils@5.0.81
- @ai-sdk/provider@4.0.38
- @texera/workflow-macros@0.0.0
- @vercel/oidc@3.2.0
- @workflow/serde@4.1.0
- ai@7.0.173
Expand Down Expand Up @@ -249,6 +250,7 @@ Agent service npm packages:
- file-type@21.1.1
- graphlib@2.1.8
- json-schema-traverse@1.0.0
- lodash-es@4.18.1
- lodash@4.18.1
- memoirist@0.4.0
- ms@2.1.3
Expand All @@ -268,6 +270,7 @@ Agent service npm packages:
- token-types@6.1.1
- uint8array-extras@1.5.0
- undici-types@7.16.0
- uuid@14.0.1
- zod@3.25.76

--------------------------------------------------------------------------------
Expand Down
14 changes: 14 additions & 0 deletions agent-service/bun.lock

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

4 changes: 4 additions & 0 deletions agent-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,21 @@
"dependencies": {
"@ai-sdk/openai": "4.0.118",
"@elysiajs/cors": "1.4.3",
"@texera/workflow-macros": "file:../common/workflow-core/src/main/typescript/workflow-macros",
"ai": "7.0.173",
"ajv": "8.20.0",
"dagre": "0.8.5",
"elysia": "1.4.32",
"lodash-es": "4.18.1",
"pino": "10.4.0",
"rxjs": "7.8.2",
"uuid": "14.0.1",
"zod": "3.25.76"
},
"devDependencies": {
"@types/bun": "1.4.4",
"@types/dagre": "0.7.54",
"@types/lodash-es": "4.17.12",
"pino-pretty": "13.2.0",
"prettier": "3.10.1",
"tsx": "4.23.15",
Expand Down
34 changes: 34 additions & 0 deletions agent-service/src/agent/macro-test-data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import fixture from "../../../common/workflow-compiler/src/test/resources/macros/nested-expansion.json";

export function macroWorkflow(leafProperty = "value") {
const content = structuredClone(fixture.content);
macroLeaf(content).formBinding.fields[0].propertyKey = leafProperty;
return content;
}

export function macroLeaf(content: typeof fixture.content) {
return content.macroDependencies[0].content.macroDependencies[0].content.macroDependencies[0].content;
}

export function macroExpansionResponse() {
return structuredClone(fixture.expected);
}
27 changes: 27 additions & 0 deletions agent-service/src/agent/texera-agent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,31 @@ describe("sendMessage", () => {
expect(res.error).toBeUndefined();
});

test("uses authoritative macro boundary schemas and nested errors in the model's context", async () => {
const { macroWorkflow, macroExpansionResponse } = await import("./macro-test-data");
const content = macroWorkflow();
const before = JSON.stringify(content);
const model = textModel("ok", 1, 1);
const agent = makeAgentWith(model);
agent.getWorkflowState().setWorkflowContent(content);
fetchSpy.mockResolvedValue({
ok: true,
json: async () => ({
macroExpansion: macroExpansionResponse(),
operatorOutputSchemas: { one: { "0_false": [{ attributeName: "boundary", attributeType: "integer" }] } },
operatorErrors: { one: { operatorId: "one", message: "Outer / Child / Scan: invalid column", type: "schema" } },
}),
} as any);

const result = await agent.sendMessage("inspect the macro");
const prompt = (model as any).doGenerateCalls[0].prompt[1].content[0].text;
expect(result.error).toBeUndefined();
expect(prompt).toContain("Output Schema: [boundary: integer]");
expect(prompt).toContain("Compilation Error: Outer / Child / Scan: invalid column");
expect(agent.getWorkflowState().getWorkflowContent()).toEqual(content);
expect(JSON.stringify(content)).toBe(before);
});

test("reports a model failure as an error step", async () => {
const model = new MockLanguageModelV4({
doGenerate: async () => {
Expand Down Expand Up @@ -1087,6 +1112,8 @@ describe("delegate mode", () => {
await agent.sendMessage("one");
const retrieves = () => urls.filter(u => u.includes("/api/workflow/7")).length;
expect(retrieves()).toBe(1);
const compileCall = fetchSpy.mock.calls.find(([url]: [unknown]) => String(url).includes("/api/compile"));
expect(compileCall?.[1]?.headers).toEqual({ Authorization: "Bearer tok", "Content-Type": "application/json" });
expect(
agent
.getWorkflowState()
Expand Down
1 change: 1 addition & 0 deletions agent-service/src/agent/texera-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ export class TexeraAgent {
const getExecutionConfig = this.delegateConfig ? () => this.buildExecutionConfig()! : undefined;

const context: ToolContext = {
userToken: this.delegateConfig?.userToken,
metadataStore: this.metadataStore,
settings: {
maxOperatorResultCharLimit: this.settings.maxOperatorResultCharLimit,
Expand Down
61 changes: 60 additions & 1 deletion agent-service/src/agent/tools/workflow-crud-tools.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
* under the License.
*/

import { describe, expect, test } from "bun:test";
import { afterEach, beforeEach, describe, expect, test, spyOn } from "bun:test";
import { createAddOperatorTool, createModifyOperatorTool, createDeleteOperatorTool } from "./workflow-crud-tools";
import { macroWorkflow } from "../macro-test-data";
import { WorkflowState } from "../workflow-state";
import { WorkflowSystemMetadata } from "../util/workflow-system-metadata";
import type { OperatorMetadata } from "../../api/backend-api";
import type { OperatorPredicate } from "../../types/workflow";

const fetchTarget: { fetch: (...args: Parameters<typeof fetch>) => ReturnType<typeof fetch> } = globalThis;

// A single synthetic operator type with one input and one output port, backed
// by a real (in-memory, no backend fetch) WorkflowSystemMetadata so the tools
// exercise the genuine schema-validation and predicate-construction paths.
Expand Down Expand Up @@ -782,3 +785,59 @@ describe("createAddOperatorTool", () => {
expect(state.getAllOperators()).toHaveLength(0);
});
});

describe("macro property edits", () => {
const content = macroWorkflow("count");
let state: WorkflowState;
let fetchSpy: ReturnType<typeof spyOn<typeof fetchTarget, "fetch">>;
const run = (id: string, value: unknown, other = {}) =>
runTool(createModifyOperatorTool(state, { ...context, userToken: "token" }), {
operatorId: id,
properties: { value },
...other,
});

beforeEach(() => {
state = new WorkflowState();
state.setWorkflowContent({
...content,
operators: [content.operators[0], { ...content.operators[1], isDisabled: true }],
});
fetchSpy = spyOn(fetchTarget, "fetch").mockResolvedValue(new Response(null, { status: 204 }));
});
afterEach(() => {
fetchSpy.mockRestore();
state.destroy();
});

test("submits the proposed pin with its bearer token and commits only accepted edits", async () => {
expect(await run("one", 42)).not.toContain("[ERROR]");
expect(state.getOperator("one")!.operatorProperties.value).toBe(42);
const before = structuredClone(state.getWorkflowContent());
for (const operator of before.operators) {
const message = "Outer / Inner / Leaf: count must be an integer";
fetchSpy.mockResolvedValueOnce(Response.json({ message }, { status: 400 }));
expect(await run(operator.operatorID, "bad", { summary: "Rename" })).toContain(message);
const [url, init] = fetchSpy.mock.calls.at(-1)!;
expect(String(url)).toEndWith("/api/compile/validate-properties");
expect(init!.headers).toMatchObject({ Authorization: "Bearer token" });
expect(JSON.parse(init!.body as string)).toEqual({
operator: { ...operator, operatorProperties: { ...operator.operatorProperties, value: "bad" } },
macroDependencies: before.macroDependencies,
});
}
expect(await run("one", 7, { summary: "Rename", inputOperatorIds: { "9": ["two"] } })).toContain("out of range");
expect(state.getWorkflowContent()).toEqual(before);
});

test("keeps a concurrent change made while validation is pending", async () => {
const validation = Promise.withResolvers<Response>();
fetchSpy.mockReturnValueOnce(validation.promise);
const pending = run("one", 42);
expect(fetchSpy).toHaveBeenCalledTimes(1);
state.updateOperatorProperties("one", { value: 20 });
validation.resolve(new Response(null, { status: 204 }));
expect(await pending).toContain("workflow changed");
expect(state.getOperator("one")!.operatorProperties.value).toBe(20);
});
});
Loading
Loading