بيئات التشغيل

المتصفح

تعمل حزمة SDK داخل صفحة الويب وتُحفظ الجلسة في localStorage. لا يتوفر قرص أو صدفة أوامر، لذا عليك توفير عمليات الملفات للوكيل.

localStorageدون منظومة ملفاتدون صدفة أوامر
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

لا ترسل مفتاح API إلى المتصفح

كل ما يوجد في الشيفرة التي تعمل لدى المستخدم يكون منشورًا. استدعِ حزمة SDK من خادمك ومرّر النتائج إلى المتصفح. تصف الصفحات التالية جهازًا يصل الوكيل إلى ملفاته، وليس مفتاحًا محفوظًا داخل الصفحة.

الجلسة

تُحفظ مؤقتًا في localStorage الخاص بأصل الموقع. وتبقى بعد إعادة تحميل الصفحة، ولا يمكن لأي أصل آخر الوصول إليها، بما في ذلك واجهات تطبيقك التي تستخدم منافذ مختلفة أثناء التطوير.

لا يوجد وصول مباشر إلى القرص

يُطلق storage.files خطأً في هذه البيئة. يحتفظ جهاز المتصفح بملفاته داخل المتصفح نفسه، ويصل الوكيل إليها عبر ست عمليات توفرها أنت.

const agent = api.agents.create({
  runtime: "local",
  machine: device,
  model: "gemini-3.5-flash",
  files: {
    list:   async (dir) => [{ name, path, type, size, mimeType, modifiedAt }],
    read:   async (path) => ({ content }),
    write:  async (path, content) => ({ path }),
    mkdir:  async (dir) => ({ path: dir }),
    move:   async (from, to) => ({ path: to }),
    remove: async (path) => ({ ok: true }),
  },
});
class DeviceFiles:
    """Any object with these six methods can be the agent's workspace."""
    def list(self, dir="", *, recursive=False): return [{"name": ..., "path": ..., "type": ..., "size": ...}]
    def read(self, path): return {"content": ...}
    def write(self, path, content): return {"path": path}
    def mkdir(self, dir): return {"path": dir}
    def move(self, source, destination): return {"path": destination}
    def remove(self, path): return {"ok": True}

agent = api.agents.create(
    runtime="local",
    machine=device,
    model="gemini-3.5-flash",
    files=DeviceFiles(),
)
غياب أي عملية يؤدي إلى رفض إنشاء الوكيل

الخطأ هو files_required، ويحدد العمليات المفقودة. لا يُنشأ الوكيل بإمكانات ناقصة.

مكان تخزين الملفات الفعلي

أنت من يختاره، وهذا هو الغرض من الجسر: IndexedDB لملفات الجهاز نفسه، أو تخزين الكائنات للملفات التي يجب أن تتبع المستخدم بين الأجهزة، أو خريطة في الذاكرة للاختبارات.

// A bridge over any async key-value store
const files = (store) => ({
  list:   async (dir = "") => store.listPrefix(dir),
  read:   async (path) => ({ content: await store.get(path) }),
  write:  async (path, content) => { await store.set(path, content); return { path }; },
  mkdir:  async (dir) => ({ path: dir }),
  move:   async (from, to) => { await store.set(to, await store.get(from)); await store.del(from); return { path: to }; },
  remove: async (path) => { await store.del(path); return { ok: true }; },
});
# A bridge over any key-value store
class StoreFiles:
    def __init__(self, store): self.store = store
    def list(self, dir="", *, recursive=False): return self.store.list_prefix(dir)
    def read(self, path): return {"content": self.store.get(path)}
    def write(self, path, content):
        self.store.set(path, content)
        return {"path": path}
    def mkdir(self, dir): return {"path": dir}
    def move(self, source, destination):
        self.store.set(destination, self.store.get(source))
        self.store.delete(source)
        return {"path": destination}
    def remove(self, path):
        self.store.delete(path)
        return {"ok": True}

تسجيل جهاز

لا يسجّل المتصفح نفسه تلقائيًا؛ فحزمة SDK ليست هناك في هذا الإعداد، ويجب ألا يكون المفتاح فيها أيضًا. يسجّل الخادم الجهاز باستخدام معرّف تحتفظ به الصفحة.

// in the page
let deviceId = localStorage.getItem("device");
if (!deviceId) {
  deviceId = crypto.randomUUID();
  localStorage.setItem("device", deviceId);
}

// on your server, with the key
const device = await api.storage.device({
  deviceId,
  name: "Zayd's phone",
  userAgent,
});
// a storage of type "phone", provider "browser"
# In the page, the browser keeps its own device id (JavaScript):
#   localStorage.getItem("device") || crypto.randomUUID()

# On your Python server, with the key
device = api.storage.device(
    device_id=device_id,
    name="Zayd's phone",
    user_agent=user_agent,
)
# a storage of type "phone", provider "browser"

الأوامر

تُزال bash من مجموعة الأدوات في هذه البيئة لعدم وجود ما ينفّذها. إذا وفّرت واجهة shell، تعود الأداة وتعمل بالطريقة نفسها من منظور الوكيل.

api.agents.create({
  runtime: "local",
  machine: device,
  model: "gemini-3.5-flash",
  files,
  shell: {
    run: async (command, { timeoutMs, signal }) => {
      const { stdout, stderr, exitCode } = await runSomewhere(command, { timeoutMs, signal });
      return { stdout, stderr, exitCode };
    },
  },
});
# Python's bash tool runs on a LocalFiles workspace, on the machine that runs the SDK.
# A device without a shell gets the file tools only: leave "bash" out of its tools.
api.agents.create(
    runtime="local",
    machine=device,
    model="gemini-3.5-flash",
    files=StoreFiles(store),
    tools=["read", "list", "glob", "write", "edit", "move", "delete"],
)

أعِد الحقول الثلاثة المطلوبة. يُرفض أي شكل آخر بالخطأ invalid_shell قبل إنشاء الوكيل.

الإمكانات غير المتاحة مباشرةً

  • storage.files — استخدم جسر files.
  • terminals — تحتاج صدفة الأوامر التي تستمر بعد الإجابة إلى عملية تستضيفها.
  • bash، ما لم توفّر shell.
  • قراءة المهارات والوكلاء الفرعيين من القرص. أما مكتبة الحساب فتبقى متاحة، وهي المكان المناسب لحفظها.