Instructions
Locate and Replace resources:
Find the line starting with resources = { and replace it and its contents with the new block above.
Replace get_resource:
Find the existing @app.route("/resources/<resource_id>", methods=["GET"]) function and replace the entire function (from @app.route to its last return) with the new get_resource block.
Add update_resource:
Insert the new update_resource function right after the get_resource function ends. Ensure it’s before the next endpoint (likely /pay).
This commit is contained in:
parent
4352ec8328
commit
5b50e5c9dc
1 changed files with 36 additions and 7 deletions
|
|
@ -123,7 +123,11 @@ tools = {
|
|||
"execute": lambda params: {"result": f"Hello, {params['name']}!"},
|
||||
},
|
||||
}
|
||||
resources = {"hello": {"id": "hello", "content": "Hello, SLOP!"}}
|
||||
resources = {
|
||||
"hello": {"id": "hello", "content": "Hello, SLOP!"},
|
||||
"foo/bar": {"id": "foo/bar", "content": "Nested Foo Bar"},
|
||||
"foo/baz": {"id": "foo/baz", "content": "Nested Foo Baz"},
|
||||
}
|
||||
|
||||
# Memory endpoints with lock and timeout
|
||||
LOCK_TIMEOUT = 2 # Seconds to wait for lock acquisition
|
||||
|
|
@ -291,13 +295,38 @@ def list_resources():
|
|||
|
||||
@app.route("/resources/<resource_id>", methods=["GET"])
|
||||
def get_resource(resource_id):
|
||||
logger.info(f"Received /resources/{resource_id} request")
|
||||
if resource_id not in resources:
|
||||
logger.error(f"Resource not found: {resource_id}")
|
||||
return jsonify({"error": "Resource not found"}), 404
|
||||
logger.info(f"Received /resources/{resource_id} GET request")
|
||||
if resource_id in resources:
|
||||
resource = resources[resource_id]
|
||||
logger.debug(f"Returning resource {resource_id}: {resource}")
|
||||
logger.debug(f"Exact match found for {resource_id}: {resource}")
|
||||
return jsonify(resource), 200
|
||||
else:
|
||||
# Prefix search for nested resources
|
||||
prefix = f"{resource_id}/"
|
||||
matching_resources = [
|
||||
res for key, res in resources.items() if key.startswith(prefix)
|
||||
]
|
||||
if matching_resources:
|
||||
logger.debug(f"Prefix search for {resource_id} found: {matching_resources}")
|
||||
return jsonify({"resources": matching_resources}), 200
|
||||
logger.warning(f"No resource or nested resources found for {resource_id}")
|
||||
return jsonify({"error": "Resource not found"}), 404
|
||||
|
||||
@app.route("/resources/<resource_id>", methods=["PUT"])
|
||||
def update_resource(resource_id):
|
||||
logger.info(f"Received /resources/{resource_id} PUT request")
|
||||
data = request.json
|
||||
logger.debug(f"Update resource data: {data}")
|
||||
if not data or "content" not in data:
|
||||
logger.warning(f"Invalid resource update request: {data}")
|
||||
return jsonify({"error": "Missing 'content'"}), 400
|
||||
# Update or create the resource
|
||||
resources[resource_id] = {
|
||||
"id": resource_id,
|
||||
"content": data["content"]
|
||||
}
|
||||
logger.info(f"Updated/created resource {resource_id}: {resources[resource_id]}")
|
||||
return jsonify({"status": "updated", "resource": resources[resource_id]}), 200
|
||||
|
||||
@app.route("/pay", methods=["POST"])
|
||||
def pay():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue