Spaces:
Running
Running
owenkaplinsky
commited on
Commit
·
59cfebc
1
Parent(s):
f946d47
Add placing blocks in output
Browse files- project/chat.py +27 -6
- project/src/index.js +30 -1
project/chat.py
CHANGED
|
@@ -135,11 +135,13 @@ def delete_block(block_id):
|
|
| 135 |
traceback.print_exc()
|
| 136 |
return f"Error deleting block: {str(e)}"
|
| 137 |
|
| 138 |
-
def create_block(block_spec, under_block_id=None):
|
| 139 |
try:
|
| 140 |
print(f"[CREATE REQUEST] Attempting to create block: {block_spec}")
|
| 141 |
if under_block_id:
|
| 142 |
print(f"[CREATE REQUEST] Under block ID: {under_block_id}")
|
|
|
|
|
|
|
| 143 |
|
| 144 |
# Generate a unique request ID
|
| 145 |
import uuid
|
|
@@ -149,10 +151,12 @@ def create_block(block_spec, under_block_id=None):
|
|
| 149 |
if request_id in creation_results:
|
| 150 |
creation_results.pop(request_id)
|
| 151 |
|
| 152 |
-
# Add to creation queue with optional under_block_id
|
| 153 |
queue_data = {"request_id": request_id, "block_spec": block_spec}
|
| 154 |
if under_block_id:
|
| 155 |
queue_data["under_block_id"] = under_block_id
|
|
|
|
|
|
|
| 156 |
creation_queue.put(queue_data)
|
| 157 |
print(f"[CREATE REQUEST] Added to queue with ID: {request_id}")
|
| 158 |
|
|
@@ -612,6 +616,16 @@ def create_gradio_interface():
|
|
| 612 |
You can create new blocks by specifying the block type and its inputs, if any.
|
| 613 |
You cannot create a `create_mcp` block, but you may edit its inputs using the dedicated tool.
|
| 614 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 615 |
There are two kinds of nesting:
|
| 616 |
|
| 617 |
1. **Statement-level nesting (main-level blocks)**
|
|
@@ -734,8 +748,12 @@ def create_gradio_interface():
|
|
| 734 |
"type": "string",
|
| 735 |
"description": "The ID of the block that you want to place this under.",
|
| 736 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
| 737 |
},
|
| 738 |
-
"required": ["command"
|
| 739 |
}
|
| 740 |
},
|
| 741 |
{
|
|
@@ -992,11 +1010,14 @@ def create_gradio_interface():
|
|
| 992 |
elif function_name == "create_block":
|
| 993 |
command = function_args.get("command", "")
|
| 994 |
under_block_id = function_args.get("under", None)
|
| 995 |
-
|
|
|
|
| 996 |
print(Fore.YELLOW + f"Agent created block with command `{command}`." + Style.RESET_ALL)
|
| 997 |
-
|
| 998 |
print(Fore.YELLOW + f"Agent created block with command `{command}`, under block ID `{under_block_id}`." + Style.RESET_ALL)
|
| 999 |
-
|
|
|
|
|
|
|
| 1000 |
result_label = "Create Operation"
|
| 1001 |
|
| 1002 |
elif function_name == "create_variable":
|
|
|
|
| 135 |
traceback.print_exc()
|
| 136 |
return f"Error deleting block: {str(e)}"
|
| 137 |
|
| 138 |
+
def create_block(block_spec, under_block_id=None, input_name=None):
|
| 139 |
try:
|
| 140 |
print(f"[CREATE REQUEST] Attempting to create block: {block_spec}")
|
| 141 |
if under_block_id:
|
| 142 |
print(f"[CREATE REQUEST] Under block ID: {under_block_id}")
|
| 143 |
+
if input_name:
|
| 144 |
+
print(f"[CREATE REQUEST] Into input: {input_name}")
|
| 145 |
|
| 146 |
# Generate a unique request ID
|
| 147 |
import uuid
|
|
|
|
| 151 |
if request_id in creation_results:
|
| 152 |
creation_results.pop(request_id)
|
| 153 |
|
| 154 |
+
# Add to creation queue with optional under_block_id and input_name
|
| 155 |
queue_data = {"request_id": request_id, "block_spec": block_spec}
|
| 156 |
if under_block_id:
|
| 157 |
queue_data["under_block_id"] = under_block_id
|
| 158 |
+
if input_name:
|
| 159 |
+
queue_data["input_name"] = input_name
|
| 160 |
creation_queue.put(queue_data)
|
| 161 |
print(f"[CREATE REQUEST] Added to queue with ID: {request_id}")
|
| 162 |
|
|
|
|
| 616 |
You can create new blocks by specifying the block type and its inputs, if any.
|
| 617 |
You cannot create a `create_mcp` block, but you may edit its inputs using the dedicated tool.
|
| 618 |
|
| 619 |
+
### Placing Blocks in MCP Inputs
|
| 620 |
+
You can place blocks directly into the MCP block's inputs using the `input` parameter:
|
| 621 |
+
- Use `input: "X0"`, `input: "X1"`, etc. to place a block into an input slot
|
| 622 |
+
- Use `input: "R0"`, `input: "R1"`, etc. to place a block into an output slot
|
| 623 |
+
- **This feature can ONLY be used with the MCP block** - you cannot place blocks into inputs of other blocks this way
|
| 624 |
+
- The block will replace whatever is currently in that input
|
| 625 |
+
|
| 626 |
+
Example: Create a text block and put it in the MCP's first input:
|
| 627 |
+
`text(inputs(TEXT: "hello"))` with `input: "X0"`
|
| 628 |
+
|
| 629 |
There are two kinds of nesting:
|
| 630 |
|
| 631 |
1. **Statement-level nesting (main-level blocks)**
|
|
|
|
| 748 |
"type": "string",
|
| 749 |
"description": "The ID of the block that you want to place this under.",
|
| 750 |
},
|
| 751 |
+
"input": {
|
| 752 |
+
"type": "string",
|
| 753 |
+
"description": "The input name of the MCP block to place this block inside (e.g., 'X0', 'R0'). Can only be used with the MCP block.",
|
| 754 |
+
},
|
| 755 |
},
|
| 756 |
+
"required": ["command"],
|
| 757 |
}
|
| 758 |
},
|
| 759 |
{
|
|
|
|
| 1010 |
elif function_name == "create_block":
|
| 1011 |
command = function_args.get("command", "")
|
| 1012 |
under_block_id = function_args.get("under", None)
|
| 1013 |
+
input_name = function_args.get("input", None)
|
| 1014 |
+
if under_block_id is None and input_name is None:
|
| 1015 |
print(Fore.YELLOW + f"Agent created block with command `{command}`." + Style.RESET_ALL)
|
| 1016 |
+
elif under_block_id:
|
| 1017 |
print(Fore.YELLOW + f"Agent created block with command `{command}`, under block ID `{under_block_id}`." + Style.RESET_ALL)
|
| 1018 |
+
elif input_name:
|
| 1019 |
+
print(Fore.YELLOW + f"Agent created block with command `{command}`, into input `{input_name}`." + Style.RESET_ALL)
|
| 1020 |
+
tool_result = create_block(command, under_block_id, input_name)
|
| 1021 |
result_label = "Create Operation"
|
| 1022 |
|
| 1023 |
elif function_name == "create_variable":
|
project/src/index.js
CHANGED
|
@@ -658,8 +658,37 @@ const setupUnifiedStream = () => {
|
|
| 658 |
if (newBlock) {
|
| 659 |
blockId = newBlock.id;
|
| 660 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 661 |
// If under_block_id is specified, attach the new block under the parent
|
| 662 |
-
if (data.under_block_id) {
|
| 663 |
const parentBlock = ws.getBlockById(data.under_block_id);
|
| 664 |
if (parentBlock) {
|
| 665 |
console.log('[SSE CREATE] Attaching to parent block:', data.under_block_id);
|
|
|
|
| 658 |
if (newBlock) {
|
| 659 |
blockId = newBlock.id;
|
| 660 |
|
| 661 |
+
// If input_name is specified, place the block into that MCP input directly
|
| 662 |
+
if (data.input_name) {
|
| 663 |
+
const mcpBlock = ws.getBlocksByType('create_mcp')[0];
|
| 664 |
+
if (mcpBlock) {
|
| 665 |
+
const input = mcpBlock.getInput(data.input_name);
|
| 666 |
+
if (input && input.connection) {
|
| 667 |
+
console.log('[SSE CREATE] Placing block into MCP input:', data.input_name);
|
| 668 |
+
// Disconnect any existing block
|
| 669 |
+
const existingBlock = input.connection.targetBlock();
|
| 670 |
+
if (existingBlock) {
|
| 671 |
+
existingBlock.unplug();
|
| 672 |
+
}
|
| 673 |
+
// Connect the new block
|
| 674 |
+
if (newBlock.outputConnection) {
|
| 675 |
+
input.connection.connect(newBlock.outputConnection);
|
| 676 |
+
console.log('[SSE CREATE] Successfully placed block into input:', data.input_name);
|
| 677 |
+
} else {
|
| 678 |
+
error = `Block has no output connection to connect to MCP input ${data.input_name}`;
|
| 679 |
+
console.error('[SSE CREATE]', error);
|
| 680 |
+
}
|
| 681 |
+
} else {
|
| 682 |
+
error = `MCP input not found: ${data.input_name}`;
|
| 683 |
+
console.error('[SSE CREATE]', error);
|
| 684 |
+
}
|
| 685 |
+
} else {
|
| 686 |
+
error = 'No MCP block found to place this block into';
|
| 687 |
+
console.error('[SSE CREATE]', error);
|
| 688 |
+
}
|
| 689 |
+
}
|
| 690 |
// If under_block_id is specified, attach the new block under the parent
|
| 691 |
+
else if (data.under_block_id) {
|
| 692 |
const parentBlock = ws.getBlockById(data.under_block_id);
|
| 693 |
if (parentBlock) {
|
| 694 |
console.log('[SSE CREATE] Attaching to parent block:', data.under_block_id);
|