mirror of
https://github.com/hansjone/oclaw.git
synced 2026-10-10 05:10:45 +08:00
新增本地 public 工具与适配器
Made-with: Cursor
This commit is contained in:
parent
4d9232f3b3
commit
d8e2f4cacc
11 changed files with 582 additions and 2 deletions
39
runtime/tools/public/local_write_file_tool.py
Normal file
39
runtime/tools/public/local_write_file_tool.py
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import Any
|
||||
|
||||
from oclaw.runtime.tools.base import ToolSpec
|
||||
from oclaw.runtime.tools.local_sdk import get_local_adapter
|
||||
|
||||
|
||||
def local_write_file_tool() -> ToolSpec:
|
||||
def _handler(args: dict[str, Any]) -> dict[str, Any]:
|
||||
path = str(args.get("path") or "").strip()
|
||||
if not path:
|
||||
return {"ok": False, "error_code": "path_required", "error": "path_required"}
|
||||
content = str(args.get("content") or "")
|
||||
mode = str(args.get("mode") or "overwrite").strip().lower()
|
||||
return get_local_adapter().write_file(path=path, content=content, mode=mode)
|
||||
|
||||
return ToolSpec(
|
||||
name="local_write_file",
|
||||
description="Write or append file content via local backend.",
|
||||
parameters={
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"path": {"type": "string", "description": "Target file path."},
|
||||
"content": {"type": "string", "description": "Content to write."},
|
||||
"mode": {"type": "string", "enum": ["overwrite", "append"], "default": "overwrite"},
|
||||
},
|
||||
"required": ["path", "content"],
|
||||
"additionalProperties": False,
|
||||
},
|
||||
handler=_handler,
|
||||
tags=frozenset({"public", "local", "workspace", "write"}),
|
||||
risk_level="high",
|
||||
timeout_s=30.0,
|
||||
read_only=False,
|
||||
)
|
||||
|
||||
|
||||
__all__ = ["local_write_file_tool"]
|
||||
Loading…
Add table
Add a link
Reference in a new issue