diff --git a/pdl-live-react/src-tauri/src/compile/beeai.rs b/pdl-live-react/src-tauri/src/compile/beeai.rs index e1c239542..c8edf3e16 100644 --- a/pdl-live-react/src-tauri/src/compile/beeai.rs +++ b/pdl-live-react/src-tauri/src/compile/beeai.rs @@ -216,7 +216,7 @@ fn call_tools(model: &String, parameters: &HashMap) -> PdlBlock { metadata: None, body: Message(MessageBlock { role: Role::Tool, - pdl__defsite: None, + pdl_defsite: None, name: Some("${ tool.function.name }".to_string()), tool_call_id: Some("${ tool.id }".to_string()), content: Box::new(Advanced(Block { diff --git a/pdl-live-react/src-tauri/src/pdl/ast.rs b/pdl-live-react/src-tauri/src/pdl/ast.rs index 3674d6a6c..0525db3f0 100644 --- a/pdl-live-react/src-tauri/src/pdl/ast.rs +++ b/pdl-live-react/src-tauri/src/pdl/ast.rs @@ -414,8 +414,8 @@ pub struct MessageBlock { pub content: Box, /// pdl_id of block that defined the `content of this message - #[serde(skip_serializing_if = "Option::is_none")] - pub pdl__defsite: Option, + #[serde(rename = "pdl__defsite", skip_serializing_if = "Option::is_none")] + pub pdl_defsite: Option, /// For example, the name of the tool that was invoked, for which this message is the tool response #[serde(skip_serializing_if = "Option::is_none")] diff --git a/pdl-live-react/src-tauri/src/pdl/interpreter.rs b/pdl-live-react/src-tauri/src/pdl/interpreter.rs index 1c2c2aba3..8a907662f 100644 --- a/pdl-live-react/src-tauri/src/pdl/interpreter.rs +++ b/pdl-live-react/src-tauri/src/pdl/interpreter.rs @@ -1081,7 +1081,7 @@ impl<'a> Interpreter<'a> { content: Box::new(PdlBlock::String(m.content.clone())), name: None, tool_call_id: None, - pdl__defsite: None, + pdl_defsite: None, }) .collect(), ); @@ -1094,7 +1094,7 @@ impl<'a> Interpreter<'a> { content: Box::new(PdlBlock::String(m.content.clone())), name: None, tool_call_id: None, - pdl__defsite: None, + pdl_defsite: None, }) .collect(), ); @@ -1476,7 +1476,7 @@ impl<'a> Interpreter<'a> { role: block.role.clone(), content: Box::new(content_trace), name: name, - pdl__defsite: None, + pdl_defsite: None, tool_call_id: tool_call_id, }), )) diff --git a/pdl-live-react/src/pdl_ast.d.ts b/pdl-live-react/src/pdl_ast.d.ts index 57841ed21..f15502b41 100644 --- a/pdl-live-react/src/pdl_ast.d.ts +++ b/pdl-live-react/src/pdl_ast.d.ts @@ -1893,7 +1893,6 @@ export type Else = | ErrorBlock | EmptyBlock | null -export type IfResult = boolean | null /** * Name of the variable used to store the result of the execution of the block. * @@ -2705,6 +2704,11 @@ export type PdlContext19 = export type PdlId19 = string | null export type PdlIsLeaf19 = true export type Kind19 = "call" +/** + * Function to call. + * + */ +export type Call = LocalizedExpression | FunctionBlock | string export type PdlTrace3 = | boolean | number @@ -3048,7 +3052,7 @@ export interface CallBlock { pdl__timing?: PdlTiming | null pdl__is_leaf?: PdlIsLeaf19 kind?: Kind19 - call: unknown + call: Call args?: unknown pdl__trace?: PdlTrace3 } @@ -3715,7 +3719,6 @@ export interface IfBlock { if: If1 then: Then1 else?: Else - if_result?: IfResult } /** * Set of definitions executed before the execution of the block. diff --git a/pdl-live-react/src/view/detail/kind/If.tsx b/pdl-live-react/src/view/detail/kind/If.tsx index a6d68509f..eb2c6c950 100644 --- a/pdl-live-react/src/view/detail/kind/If.tsx +++ b/pdl-live-react/src/view/detail/kind/If.tsx @@ -1,28 +1,36 @@ +import { match, P } from "ts-pattern" import Group from "../Group" +import { stringify } from "yaml" export default function ModelItems({ - block: { if: condition, if_result }, + block: { if: condition }, }: { block: import("../../../pdl_ast").IfBlock }) { return ( <> - {typeof condition === "string" && ( - - )} - {if_result !== undefined && ( - - )} + {match(condition) + .with(P.string, (cond) => ( + + )) + .with({ pdl__expr: P._ }, (cond) => ( + + )) + .otherwise((cond) => ( + + ))} + {match(condition) + .with({ pdl__result: P.boolean }, (cond) => ( + + )) + .otherwise(() => false)} ) } diff --git a/pdl-live-react/src/view/timeline/model.ts b/pdl-live-react/src/view/timeline/model.ts index de723cdea..c384c3e70 100644 --- a/pdl-live-react/src/view/timeline/model.ts +++ b/pdl-live-react/src/view/timeline/model.ts @@ -1,4 +1,4 @@ -import { match } from "ts-pattern" +import { match, P } from "ts-pattern" import { type PdlBlock } from "../../pdl_ast" import { @@ -127,9 +127,10 @@ export function childrenOf(block: NonScalarPdlBlock) { .with({ kind: "code" }, (data) => [data.pdl__result]) .with({ kind: "get" }, (data) => [data.pdl__result]) .with({ kind: "data" }, (data) => [data.pdl__result]) - .with({ kind: "if" }, (data) => - data.if_result ? [data.then] : [data.else], + .with({ kind: "if", if: { pdl__result: P._ } }, (data) => + data.if.pdl__result ? [data.then] : [data.else], ) + .with({ kind: "if" }, (data) => [data.then, data.else]) .with({ kind: "match" }, (data) => [data.with]) // TODO .with({ kind: "read" }, (data) => [data.pdl__result]) .with({ kind: "include" }, (data) => [data.pdl__trace ?? data.pdl__result]) diff --git a/src/pdl/pdl-schema.json b/src/pdl/pdl-schema.json index 5b3fa4fa3..17a6c3f60 100644 --- a/src/pdl/pdl-schema.json +++ b/src/pdl/pdl-schema.json @@ -1330,7 +1330,9 @@ { "$ref": "#/$defs/LocalizedExpression_TypeVar_" }, - {}, + { + "$ref": "#/$defs/FunctionBlock" + }, { "type": "string" } @@ -5245,18 +5247,6 @@ "default": null, "description": "Branch to execute if the condition is false.\n ", "title": "Else" - }, - "if_result": { - "anyOf": [ - { - "type": "boolean" - }, - { - "type": "null" - } - ], - "default": null, - "title": "If Result" } }, "required": [ diff --git a/src/pdl/pdl_ast.py b/src/pdl/pdl_ast.py index abbe6cfdb..396fe7570 100644 --- a/src/pdl/pdl_ast.py +++ b/src/pdl/pdl_ast.py @@ -355,10 +355,10 @@ class Block(BaseModel): Typical roles are `system`, `user`, and `assistant`, but there may be other roles such as `available_tools`. """ + # Fields for internal use pdl__context: Optional[ModelInput] = [] """Current context """ - # Fields for internal use pdl__id: Optional[str] = "" """Unique identifier for this block """ @@ -406,7 +406,7 @@ class CallBlock(LeafBlock): """Calling a function.""" kind: Literal[BlockKind.CALL] = BlockKind.CALL - call: ExpressionType + call: ExpressionType[FunctionBlock] """Function to call. """ args: ExpressionType = {} @@ -740,8 +740,6 @@ class IfBlock(StructuredBlock): else_: Optional["BlockType"] = Field(default=None, alias="else") """Branch to execute if the condition is false. """ - # Field for internal use - if_result: Optional[bool] = None class MatchCase(BaseModel): diff --git a/src/pdl/pdl_dumper.py b/src/pdl/pdl_dumper.py index ae8394fe5..84f2218c1 100644 --- a/src/pdl/pdl_dumper.py +++ b/src/pdl/pdl_dumper.py @@ -218,8 +218,6 @@ def block_to_dict( # noqa: C901 d["then"] = block_to_dict(block.then, json_compatible) if block.else_ is not None: d["else"] = block_to_dict(block.else_, json_compatible) - if block.if_result is not None: - d["if_result"] = block.if_result case MatchBlock(): d["match"] = expr_to_dict(block.match_, json_compatible) d["with"] = [ diff --git a/src/pdl/pdl_interpreter.py b/src/pdl/pdl_interpreter.py index b36e080f3..9b1fee1b3 100644 --- a/src/pdl/pdl_interpreter.py +++ b/src/pdl/pdl_interpreter.py @@ -688,7 +688,6 @@ def process_block_body( trace = trace.model_copy( update={ "condition": if_trace, - "if_result": b, } ) case MatchBlock():