Spaces:
Running
Running
owenkaplinsky commited on
Commit ·
fb93b41
1
Parent(s): 4253088
Make IF simpler
Browse files- project/blocks.txt +1 -1
- project/chat.py +12 -8
- project/src/index.js +18 -19
project/blocks.txt
CHANGED
|
@@ -7,7 +7,7 @@ VALUE: make_json(inputs(KEYN: value, FIELDN: value)) // N starts at 0; you can m
|
|
| 7 |
VALUE: call_api(inputs(METHOD: "GET/POST/PUT/DELETE", URL: value, HEADERS: value)) // HEADERS is optional
|
| 8 |
|
| 9 |
# Logic
|
| 10 |
-
STATEMENT: controls_if(inputs(
|
| 11 |
VALUE: logic_negate(inputs())
|
| 12 |
VALUE: logic_boolean(inputs(BOOL: "TRUE/FALSE"))
|
| 13 |
VALUE: logic_null(inputs())
|
|
|
|
| 7 |
VALUE: call_api(inputs(METHOD: "GET/POST/PUT/DELETE", URL: value, HEADERS: value)) // HEADERS is optional
|
| 8 |
|
| 9 |
# Logic
|
| 10 |
+
STATEMENT: controls_if(inputs(IF0: value, IF1: value, IF2: value, ELSE)) // IF0 is REQUIRED (the main condition). IF1, IF2, IF3, etc are OPTIONAL (additional else-if conditions). ELSE is OPTIONAL (no value needed, just include the word). DO NOT use input_name with controls_if creation; specify all conditions in the inputs. After creating, use input_name to place statements: "DO0" (IF then-statements), "DO1" (first ELSE-IF then-statements), "DO2" (second ELSE-IF then-statements), "ELSE" (final else statements)
|
| 11 |
VALUE: logic_negate(inputs())
|
| 12 |
VALUE: logic_boolean(inputs(BOOL: "TRUE/FALSE"))
|
| 13 |
VALUE: logic_null(inputs())
|
project/chat.py
CHANGED
|
@@ -617,19 +617,21 @@ def create_gradio_interface():
|
|
| 617 |
The entire IF/ELSE structure must be created in one `create_block` call.
|
| 618 |
|
| 619 |
**Structure:**
|
| 620 |
-
`controls_if(inputs(
|
| 621 |
|
| 622 |
-
- `
|
| 623 |
-
- `
|
| 624 |
- `ELSE` keyword (optional, no value)
|
| 625 |
|
| 626 |
**Do NOT:**
|
| 627 |
- Add ELSE or ELSE-IF later using `input_name`
|
| 628 |
- Give ELSE a value
|
|
|
|
| 629 |
|
| 630 |
**Correct placement after creation:**
|
| 631 |
-
- `input_name: "DO0"`: IF branch
|
| 632 |
-
- `input_name: "DO1"`:
|
|
|
|
| 633 |
- `input_name: "ELSE"`: ELSE branch
|
| 634 |
|
| 635 |
YOU CANNOT EDIT THE IF BLOCK LATER. IF YOU WILL NEED TO HAVE AN ELSE OR IFELSE LATER, YOU MUST CREATE IT WITH ALL BRANCHES FROM THE START.
|
|
@@ -731,6 +733,8 @@ def create_gradio_interface():
|
|
| 731 |
|
| 732 |
Always build the container/assignment block FIRST, then construct the value expression INSIDE it, both in a single call.
|
| 733 |
|
|
|
|
|
|
|
| 734 |
### No Early Returns in Conditionals
|
| 735 |
|
| 736 |
Blockly does not support early returns from within conditional branches. You MUST use a variable to store the result and return that variable in the MCP output:
|
|
@@ -753,6 +757,7 @@ def create_gradio_interface():
|
|
| 753 |
Before creating or deleting any blocks, always begin with a *Planning Phase*:
|
| 754 |
|
| 755 |
0. Acknowledge the `VALUE BLOCK CONSTRUCTION: ABSOLUTE RULE` section and how you are prohibited from doing multi step calls for value blocks, and must do it in one create block call.
|
|
|
|
| 756 |
|
| 757 |
1. **Analyze the user's request.** Identify all required inputs, outputs, intermediate steps, loops, and conditionals.
|
| 758 |
|
|
@@ -807,7 +812,7 @@ def create_gradio_interface():
|
|
| 807 |
# Throwaway parameter to get the agent to think about IF rules.
|
| 808 |
"if_notes": {
|
| 809 |
"type": "string",
|
| 810 |
-
"description": "If you are going to make an if statement, YOU ARE REQUIRED TO USE THIS. Write the amount if IF/IFELSE/ELSE you will need.",
|
| 811 |
},
|
| 812 |
"command": {
|
| 813 |
"type": "string",
|
|
@@ -827,7 +832,7 @@ def create_gradio_interface():
|
|
| 827 |
"description": "ONLY for two cases: placing value blocks into MCP output slots using 'R<N>', and placing statement blocks into specific branches of controls_if (DO0, DO1, ELSE). NEVER USE THIS PARAMETER UNLESS YOU ARE DOING ONE OF THOSE TWO EXACT THINGS.",
|
| 828 |
},
|
| 829 |
},
|
| 830 |
-
"required": ["command"],
|
| 831 |
}
|
| 832 |
},
|
| 833 |
{
|
|
@@ -1048,7 +1053,6 @@ def create_gradio_interface():
|
|
| 1048 |
|
| 1049 |
# PROCESSING TOOL CALLS
|
| 1050 |
if tool_calls:
|
| 1051 |
-
|
| 1052 |
# Show assistant text FIRST if it exists
|
| 1053 |
if ai_response:
|
| 1054 |
if accumulated_response:
|
|
|
|
| 617 |
The entire IF/ELSE structure must be created in one `create_block` call.
|
| 618 |
|
| 619 |
**Structure:**
|
| 620 |
+
`controls_if(inputs(IF0: cond, IF1: cond2, IF2: cond3, ELSE))`
|
| 621 |
|
| 622 |
+
- `IF0:` first/main condition (required)
|
| 623 |
+
- `IF1:`, `IF2:`, `IF3:`, etc. - else-if conditions (optional)
|
| 624 |
- `ELSE` keyword (optional, no value)
|
| 625 |
|
| 626 |
**Do NOT:**
|
| 627 |
- Add ELSE or ELSE-IF later using `input_name`
|
| 628 |
- Give ELSE a value
|
| 629 |
+
- Use `IF:` alone without a number (must be `IF0`)
|
| 630 |
|
| 631 |
**Correct placement after creation:**
|
| 632 |
+
- `input_name: "DO0"`: Main IF branch
|
| 633 |
+
- `input_name: "DO1"`: First ELSE-IF branch
|
| 634 |
+
- `input_name: "DO2"`: Second ELSE-IF branch
|
| 635 |
- `input_name: "ELSE"`: ELSE branch
|
| 636 |
|
| 637 |
YOU CANNOT EDIT THE IF BLOCK LATER. IF YOU WILL NEED TO HAVE AN ELSE OR IFELSE LATER, YOU MUST CREATE IT WITH ALL BRANCHES FROM THE START.
|
|
|
|
| 733 |
|
| 734 |
Always build the container/assignment block FIRST, then construct the value expression INSIDE it, both in a single call.
|
| 735 |
|
| 736 |
+
Creating variables is not sufficient on its own. In addition to that, you MUST not forget to return the variable in the MCP block output slot.
|
| 737 |
+
|
| 738 |
### No Early Returns in Conditionals
|
| 739 |
|
| 740 |
Blockly does not support early returns from within conditional branches. You MUST use a variable to store the result and return that variable in the MCP output:
|
|
|
|
| 757 |
Before creating or deleting any blocks, always begin with a *Planning Phase*:
|
| 758 |
|
| 759 |
0. Acknowledge the `VALUE BLOCK CONSTRUCTION: ABSOLUTE RULE` section and how you are prohibited from doing multi step calls for value blocks, and must do it in one create block call.
|
| 760 |
+
Then also acknowledge that you are required to set values in all MCP block output slots, and cannot forget and leave them empty.
|
| 761 |
|
| 762 |
1. **Analyze the user's request.** Identify all required inputs, outputs, intermediate steps, loops, and conditionals.
|
| 763 |
|
|
|
|
| 812 |
# Throwaway parameter to get the agent to think about IF rules.
|
| 813 |
"if_notes": {
|
| 814 |
"type": "string",
|
| 815 |
+
"description": "If you are going to make an if statement, YOU ARE REQUIRED TO USE THIS. Write the amount if IF/IFELSE/ELSE you will need. You MUST use this amount in the command. If you aren't making an if, say 'N/A'.",
|
| 816 |
},
|
| 817 |
"command": {
|
| 818 |
"type": "string",
|
|
|
|
| 832 |
"description": "ONLY for two cases: placing value blocks into MCP output slots using 'R<N>', and placing statement blocks into specific branches of controls_if (DO0, DO1, ELSE). NEVER USE THIS PARAMETER UNLESS YOU ARE DOING ONE OF THOSE TWO EXACT THINGS.",
|
| 833 |
},
|
| 834 |
},
|
| 835 |
+
"required": ["if_notes", "command"],
|
| 836 |
}
|
| 837 |
},
|
| 838 |
{
|
|
|
|
| 1053 |
|
| 1054 |
# PROCESSING TOOL CALLS
|
| 1055 |
if tool_calls:
|
|
|
|
| 1056 |
# Show assistant text FIRST if it exists
|
| 1057 |
if ai_response:
|
| 1058 |
if accumulated_response:
|
project/src/index.js
CHANGED
|
@@ -691,9 +691,10 @@ const setupUnifiedStream = () => {
|
|
| 691 |
console.log('[SSE CREATE] controls_if inputs:', inputs);
|
| 692 |
|
| 693 |
// Process condition inputs and store block objects
|
|
|
|
| 694 |
for (const [key, value] of Object.entries(inputs)) {
|
| 695 |
-
if (key
|
| 696 |
-
// This is a condition block specification (
|
| 697 |
conditionBlocks[key] = value;
|
| 698 |
|
| 699 |
if (typeof value === 'string' && value.match(/^\w+\s*\(inputs\(/)) {
|
|
@@ -709,10 +710,10 @@ const setupUnifiedStream = () => {
|
|
| 709 |
}
|
| 710 |
}
|
| 711 |
|
| 712 |
-
// Count
|
| 713 |
let elseIfCount = 0;
|
| 714 |
for (const key of Object.keys(conditionBlocks)) {
|
| 715 |
-
if (key.match(/^
|
| 716 |
elseIfCount++;
|
| 717 |
}
|
| 718 |
}
|
|
@@ -813,35 +814,33 @@ const setupUnifiedStream = () => {
|
|
| 813 |
const conditionBlockObjects = newBlock.pendingConditionBlockObjects_;
|
| 814 |
console.log('[SSE CREATE] Connecting condition blocks:', Object.keys(conditionBlockObjects));
|
| 815 |
|
| 816 |
-
// Connect the
|
| 817 |
-
if (conditionBlockObjects['
|
| 818 |
-
const ifBlock = conditionBlockObjects['
|
| 819 |
const input = newBlock.getInput('IF0');
|
| 820 |
console.log('[SSE CREATE] IF0 input exists?', !!input);
|
| 821 |
if (input && input.connection && ifBlock.outputConnection) {
|
| 822 |
ifBlock.outputConnection.connect(input.connection);
|
| 823 |
-
console.log('[SSE CREATE] Connected
|
| 824 |
} else {
|
| 825 |
-
console.warn('[SSE CREATE] Could not connect
|
| 826 |
}
|
| 827 |
}
|
| 828 |
|
| 829 |
-
// Connect
|
| 830 |
-
console.log('[SSE CREATE] Processing', newBlock.pendingElseifCount_, '
|
| 831 |
-
for (let i =
|
| 832 |
-
const key = '
|
| 833 |
console.log('[SSE CREATE] Looking for key:', key, 'exists?', !!conditionBlockObjects[key]);
|
| 834 |
if (conditionBlockObjects[key]) {
|
| 835 |
const ifElseBlock = conditionBlockObjects[key];
|
| 836 |
-
|
| 837 |
-
|
| 838 |
-
const input = newBlock.getInput(inputName);
|
| 839 |
-
console.log('[SSE CREATE] Input', inputName, 'exists?', !!input);
|
| 840 |
if (input && input.connection && ifElseBlock.outputConnection) {
|
| 841 |
ifElseBlock.outputConnection.connect(input.connection);
|
| 842 |
-
console.log('[SSE CREATE] Connected
|
| 843 |
} else {
|
| 844 |
-
console.warn('[SSE CREATE] Could not connect
|
| 845 |
}
|
| 846 |
}
|
| 847 |
}
|
|
|
|
| 691 |
console.log('[SSE CREATE] controls_if inputs:', inputs);
|
| 692 |
|
| 693 |
// Process condition inputs and store block objects
|
| 694 |
+
// Blockly uses IF0, IF1, IF2... not IF, IFELSEN0, IFELSEN1
|
| 695 |
for (const [key, value] of Object.entries(inputs)) {
|
| 696 |
+
if (key.match(/^IF\d+$/)) {
|
| 697 |
+
// This is a condition block specification (IF0, IF1, IF2, ...)
|
| 698 |
conditionBlocks[key] = value;
|
| 699 |
|
| 700 |
if (typeof value === 'string' && value.match(/^\w+\s*\(inputs\(/)) {
|
|
|
|
| 710 |
}
|
| 711 |
}
|
| 712 |
|
| 713 |
+
// Count IFELSE (else-if) blocks: IF1, IF2, IF3... (IF0 is the main if, not an else-if)
|
| 714 |
let elseIfCount = 0;
|
| 715 |
for (const key of Object.keys(conditionBlocks)) {
|
| 716 |
+
if (key.match(/^IF\d+$/) && key !== 'IF0') {
|
| 717 |
elseIfCount++;
|
| 718 |
}
|
| 719 |
}
|
|
|
|
| 814 |
const conditionBlockObjects = newBlock.pendingConditionBlockObjects_;
|
| 815 |
console.log('[SSE CREATE] Connecting condition blocks:', Object.keys(conditionBlockObjects));
|
| 816 |
|
| 817 |
+
// Connect the IF0 condition
|
| 818 |
+
if (conditionBlockObjects['IF0']) {
|
| 819 |
+
const ifBlock = conditionBlockObjects['IF0'];
|
| 820 |
const input = newBlock.getInput('IF0');
|
| 821 |
console.log('[SSE CREATE] IF0 input exists?', !!input);
|
| 822 |
if (input && input.connection && ifBlock.outputConnection) {
|
| 823 |
ifBlock.outputConnection.connect(input.connection);
|
| 824 |
+
console.log('[SSE CREATE] Connected IF0 condition');
|
| 825 |
} else {
|
| 826 |
+
console.warn('[SSE CREATE] Could not connect IF0 - input:', !!input, 'childConnection:', !!ifBlock.outputConnection);
|
| 827 |
}
|
| 828 |
}
|
| 829 |
|
| 830 |
+
// Connect IF1, IF2, IF3... (else-if conditions)
|
| 831 |
+
console.log('[SSE CREATE] Processing', newBlock.pendingElseifCount_, 'else-if conditions');
|
| 832 |
+
for (let i = 1; i <= newBlock.pendingElseifCount_; i++) {
|
| 833 |
+
const key = 'IF' + i;
|
| 834 |
console.log('[SSE CREATE] Looking for key:', key, 'exists?', !!conditionBlockObjects[key]);
|
| 835 |
if (conditionBlockObjects[key]) {
|
| 836 |
const ifElseBlock = conditionBlockObjects[key];
|
| 837 |
+
const input = newBlock.getInput(key);
|
| 838 |
+
console.log('[SSE CREATE] Input', key, 'exists?', !!input);
|
|
|
|
|
|
|
| 839 |
if (input && input.connection && ifElseBlock.outputConnection) {
|
| 840 |
ifElseBlock.outputConnection.connect(input.connection);
|
| 841 |
+
console.log('[SSE CREATE] Connected', key, 'condition');
|
| 842 |
} else {
|
| 843 |
+
console.warn('[SSE CREATE] Could not connect', key, '- input exists:', !!input, 'has connection:', input ? !!input.connection : false, 'childHasOutput:', !!ifElseBlock.outputConnection);
|
| 844 |
}
|
| 845 |
}
|
| 846 |
}
|