# :

Canonical URL: https://developers.iagenify.com/ar/sdk/agent/events/permission/
Language: ar

`{ type: "permission", id, tool, category, args, mode }`

يُطلب شيء ما ، يُنْشَأ قبل ان يُنتظر ردّك على اتصالك ، اي ما يترك واجهة تدهن الحوار بينما ينتظر الوعد النقرة .

Status: before the callback · permission_result follows · the whole args

## الحقول {#fields}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `id` | string |  | أداة دعوة أداة معر مُعرَف - نفس `tool_start` سوف يُحمل |
| `tool` | string |  | ما المطلوب منه |
| `category` | string |  | جمهورية [الفئة الاجتماعية](/ar/sdk/agent/permissions/categories). |
| `args` | object |  | الحجج الفعلية، هذا ما يجب أن يظهره الشخص |
| `mode` | string |  | النسق المعمول به في هذه اللحظة. |

## نمط الإنسان في لووب {#pattern}

```javascript
const pending = new Map();

const agent = api.agents.create({
  runtime: "local", machine: pc, model, mode: "ask",

  // The promise is what the loop waits on
  onPermission: ({ id }) => new Promise((resolve) => pending.set(id, resolve)),

  // The event is what paints the dialog
  onEvent: (e) => {
    if (e.type === "permission") showDialog(e.id, e.tool, e.category, e.args);
    if (e.type === "permission_result") closeDialog(e.id, e.decision);
  },
});

// When the person clicks
function answer(id, decision) { pending.get(id)?.(decision); pending.delete(id); }
```

## permission_result {#result}

```javascript
{ type: "permission_result", id, tool, decision }   // "once" | "always" | "deny"
```

يتم انبعاثه بعد قرارات ردك على الطلب مع ما تقرر `true` & `once`; `false`, `null` ولا شيء من هذا `deny`.

> **ولأغراض الإرسال والنشر والنقود، يُبلغ عن ”دائما“ على أنها ”مرة واحدة“**
>
> هؤلاء الثلاثة يقبلون الإجابة ويعاملونها على أنها موافقة واحدة، لذا فإن الحدث الناتج يقول مرة واحدة. النداء التالي يطلب مرة أخرى، أياً كان النقر.

## When no event is emitted at all {#not-emitted}

- A `read`, `memory` أو `task` -مسموح به دائماً
- نمط الخطة الرافض للتغيير - مرفوض صراحة، وفقط `tool_end` يُنْقَلُ.
- Full mode allowing one of the four it opens.
- نداء يغطيه "دائماً" ذكر من قبل

إذاً غياب التنبيه ليس غياب الإيجاب: `tool_start` ما يخبرك أن شيئاً ما يحدث

> **تصل أحداث الوكلاء الفرعيين إلى هنا أيضًا**
>
> وهم يحملون اسم من النوع الأول - هوية نداء المهمة الذي بدأهم - والعامل، اسمه. هويتهم الخاصة مُمهدة مع المهمة، لذا لا يصطدم اثنان أبدا. اختبر المُنَصَف قبل أن تُعامل حدثا ما على أنه الركض الرئيسي.

- [الأذونات](/ar/sdk/agent/permissions): العوده و ترتيب القرارات
- [tool_start](/ar/sdk/agent/events/tool-start): ما يلي الموافقة.

```python
import threading

pending = {}

def on_permission(request):
    # The Python callback is synchronous: block this run's thread until the person answers
    answered = threading.Event()
    pending[request["id"]] = {"event": answered, "decision": "deny"}
    answered.wait()
    return pending.pop(request["id"])["decision"]

def on_event(event):
    if event["type"] == "permission":
        show_dialog(event["id"], event["tool"], event["category"], event["args"])
    if event["type"] == "permission_result":
        close_dialog(event["id"], event["decision"])

agent = api.agents.create(runtime="local", machine=pc, model=model, mode="ask", on_permission=on_permission)

# When the person clicks (from another thread)
def answer(call_id, decision):
    pending[call_id]["decision"] = decision
    pending[call_id]["event"].set()
```

```python
{"type": "permission_result", "id": ..., "tool": ..., "decision": ...}   # "once" | "always" | "deny"
```
