六、六、六、六、六、六、六、六、六、六、六、六、六、六、六、六、六、六、六、六、六、六、六、六、六、六、六、六、六
const bridge = {
async list(dir, { recursive } = {}) { /* → [{ name, path, type, size, mimeType, modifiedAt }] */ },
async read(path) { /* → { …item, content } — string or bytes */ },
async write(path, content) { /* → item */ },
async mkdir(path) { /* → item */ },
async move(from, to) { /* → item */ },
async remove(path) { /* → { ok: true } */ },
};class Bridge:
def list(self, dir="", *, recursive=False): ... # → [{"name", "path", "type", "size"}]
def read(self, path): ... # → {…item, "content"} — str or bytes
def write(self, path, content): ... # → item
def mkdir(self, path): ... # → item
def move(self, source, destination): ... # → item
def remove(self, path): ... # → {"ok": True}故意故意 本地文件自己的形状: 任何针对一个作品的 任何反对另一个作品的 任何写作 代理商都无法知道它拥有什么
全部六人均需
空桥在创建时被拒绝 files_required半个文件系统在工具需要丢失的碎片时会失败——这是最糟糕的发现时间。
引擎对它们的期望
| 预测 | 原因 |
|---|---|
| 路径相对, 向前斜线 | 每个工具都通过它们,没有改变。 |
| 路径路径不能离开工作空间 | 这座桥梁是边界——执行它。 |
read 返回文本的字符串,否则返回字节 | 引擎决定从类型中附加什么 。 |
以点开头的条目从 list | 版本、循环文件夹和会话日记必须让路。 |
| 错误带有代码 | path_not_found 和 not_a_folder 被理解;任何其他表面都作为工具的失败。 |
万物皆经过
read, write, edit, glob, grep、 生成的媒体, 检查站 和 日记 全部使用。 文件没有第二条路径—— 这使得手机浏览器存储一个完整的工作空间, 而不是一个部分的工作空间。
桥梁可以远距离
// Each operation is streamed to the page that holds the files,
// run there, and answered back.
const phoneBridge = () => Object.fromEntries(
["list", "read", "write", "mkdir", "move", "remove"].map((op) => [
op,
(...args) => askThePage({ op, args }), // resolves when the page answers
]),
);# Each operation is sent to whatever holds the files, run there, and answered back
class PhoneBridge:
def __getattr__(self, op):
if op not in ("list", "read", "write", "mkdir", "move", "remove"):
raise AttributeError(op)
return lambda *args, **kwargs: ask_the_page({"op": op, "args": args, "kwargs": kwargs})给它一个自己超时的间隔: 停止回答的页面会永久地等待。 拒绝承诺会结束工具呼叫, 错误会让模式行动 。
叫做"很多"
单单 grep 检查站读取它记录的所有文件。远程桥应该分批或缓存,只要它能够——发动机不试图节俭,因为磁盘上不需要。