wexa 0.5.0__tar.gz → 0.7.0.dev104__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: wexa
3
- Version: 0.5.0
3
+ Version: 0.7.0.dev104
4
4
  Summary: Python client for Wexa Fabric
5
5
  License: Proprietary
6
6
  Project-URL: Homepage, https://fabric.wexa.ai
@@ -134,25 +134,28 @@ the *permission* is what's wrong. Fix the key, not the payload.
134
134
 
135
135
  ### Which grant does each call need?
136
136
 
137
- Fifteen grants cover the sixty tools in this client:
137
+ Sixteen grants cover sixty-nine of the seventy-one tools in this client. The other two,
138
+ `request_approval` and `get_approval`, need no grant, the same as `approvals()`:
138
139
 
139
140
  | Grant | Opens |
140
141
  |---|---|
141
- | `fabric:query.read` | `query_context`, `search_code`, `fetch_code`, `connector_read` |
142
+ | `fabric:query.read` | `query_context`, `graph_stats`, `graph_subgraph`, `search_code`, `fetch_code`, `connector_read` |
142
143
  | `fabric:ontology.write` | `save_context`, `create_ontology`, `delete_context` |
143
144
  | `fabric:docs.read` | `docs` |
144
- | `fabric:orchestrate.read` | `list_skills`, `list_connectors`, `get_connector_sync`, `list_models`, `list_agents`, `get_agent`, `get_process_flow`, `get_execution`, `knowledge_base_retrieve`, `agent_versions`, `flow_versions`, `list_schedules`, `get_schedule`, `list_triggers`, `list_peer_agents`, `handshake_peer_agent` |
145
+ | `fabric:orchestrate.read` | `list_skills`, `list_connectors`, `get_connector_sync`, `list_connector_catalog`, `get_connector_form`, `list_om_catalog`, `get_om_connection_form`, `list_connector_access_scopes`, `get_connector_ingestion`, `list_user_connectors`, `get_user_connector`, `list_models`, `list_agents`, `get_agent`, `list_process_flows`, `get_process_flow`, `get_execution`, `knowledge_base_retrieve`, `agent_versions`, `flow_versions`, `list_schedules`, `get_schedule`, `list_triggers`, `list_peer_agents`, `handshake_peer_agent`, `get_whatsapp_connection` |
145
146
  | `fabric:orchestrate.write` | `create_process_flow`, `update_process_flow`, `create_agent`, `update_agent`, `delete_agent`, `knowledge_base_add`, `promote_flow`, `rollback_flow_version`, `rollback_agent_version`, `create_schedule`, `update_schedule`, `delete_schedule`, `set_triggers`, `register_peer_agent`, `delete_peer_agent` |
146
- | `fabric:agent.run` | `run_agent`, `run_process_flow` |
147
- | `fabric:skill.write` | `provision_connector` |
147
+ | `fabric:agent.run` | `run_agent`, `run_process_flow`, `restart_execution`, `pause_execution`, `resume_execution` |
148
+ | `fabric:skill.write` | `provision_connector`, `configure_connector`, `delete_connector`, `request_connector`, `import_connector_spec`, `save_user_connector`, `test_user_connector_action`, `publish_user_connector`, `delete_user_connector` |
148
149
  | `fabric:model.write` | `set_model` |
149
150
  | `fabric:model.run` | `run_model` |
150
151
  | `fabric:connector.run` | `run_connector_action` |
151
152
  | `fabric:connector.sync` | `sync_connector` |
153
+ | `fabric:connector.connect` | `connect_whatsapp`, `complete_whatsapp_connection` |
152
154
  | `fabric:flow.delete` | `delete_process_flow` |
153
155
  | `fabric:kb.delete` | `delete_kb_document` |
154
156
  | `fabric:table.read` | `list_tables`, `get_table`, `query_table_rows` |
155
157
  | `fabric:table.write` | `create_table`, `rename_table`, `delete_table`, `insert_table_rows`, `update_table_row`, `delete_table_rows`, `add_column`, `edit_column`, `delete_column` |
158
+ | none | `request_approval`, `get_approval` |
156
159
 
157
160
  Reads and writes are separate grants, and *running* something is separate from
158
161
  *authoring* it — a credential can be allowed to run a process flow without being
@@ -264,6 +267,27 @@ Each call uses the overlap of this list and the user's current role, so a later
264
267
  role downgrade still narrows the session. Asking for a grant the role does not
265
268
  have fails at login with `ValidationError`.
266
269
 
270
+ ### Choose a project and create an independent session
271
+
272
+ ```python
273
+ m = Fabric.list_projects(workspace, email, password) # no session is made
274
+ # m["projects"]: [{"id", "name", "org_id", "role", "status"}, ...]
275
+ fabric = Fabric.login(workspace, email, password, m["projects"][0]["id"])
276
+ fabric.my_projects() # the same list from a session, no password
277
+ fabric.names() # org_name, project_name, user_name for the current scope
278
+
279
+ # A separate process gets its own session and rotating refresh token:
280
+ job = fabric.connect_project(on_tokens=save_job_tokens)
281
+ ```
282
+
283
+ `connect_project` acts with the user's role (pass a `project_id` for another of
284
+ their projects, `grants` to narrow). Its refresh token lasts 30 days from its last
285
+ use, and it ends like any session (password change, suspension, removal, revoke).
286
+
287
+ This separates refresh-token ownership; it does not introduce another request
288
+ transport. Ordinary SDK methods still accept an API key, an OAuth bearer token
289
+ or an SDK session.
290
+
267
291
  ### What can go wrong
268
292
 
269
293
  | Exception | When |
@@ -304,18 +328,77 @@ yourself — see [Arguments the server owns](#arguments-the-server-owns).
304
328
 
305
329
  Needs `fabric:query.read`.
306
330
 
331
+ ### Which projects a query reads
332
+
333
+ | Filter | Reads |
334
+ |---|---|
335
+ | `n.project_id = $project_id` | This project, plus the projects that org-shared connectors and data sources shared with this project write into |
336
+ | `n.project_id IN $project_ids` | Every project you can access |
337
+
338
+ The server binds both from your credential. On servers built before 10 October
339
+ 2026, `= $project_id` also matched every other project you can access; to be sure
340
+ of one project there, check `project_id` in the rows you get back. The map form
341
+ `(n {project_id: $project_id})` reads only this project. Do not put `project_id`
342
+ or `project_ids` in `parameters`: a `project_id` other than your own is refused.
343
+
344
+ ### Passing values: `parameters`
345
+
346
+ ```python
347
+ rows = fabric.query_context(
348
+ query="""
349
+ MATCH (t:Ticket)
350
+ WHERE t.project_id = $project_id
351
+ AND t.status IN $statuses
352
+ AND t.due >= $from AND t.due < $to
353
+ RETURN t.id AS id, t.due AS due
354
+ ORDER BY due
355
+ LIMIT 200
356
+ """,
357
+ parameters={"statuses": ["open", "blocked"], "from": "2026-10-15", "to": "2026-10-29"},
358
+ )
359
+ ```
360
+
361
+ Refer to each value as `$name` instead of pasting it into the query text. Range
362
+ comparisons (`>=`, `<`, …) work on any property. Values are stored exactly as
363
+ `save_context` received them: a number stays a number, and a date sent as text
364
+ stays text. Text compares character by character, so a range filter on a date
365
+ stored as text only works when the date is ISO 8601 (`2026-10-15`); `10/15/2026`
366
+ sorts wrongly across months and years.
367
+
368
+ ### Rows and time
369
+
370
+ - **Rows:** without a `LIMIT` the server adds `LIMIT 100`, and a `LIMIT` above
371
+ 1000 is reduced to 1000. `limit=N` sets the `LIMIT` added when the query has
372
+ none and caps any `LIMIT` it has (1 or more; above 1000 it is reduced to 1000).
373
+ - **Time:** a call has about 25 seconds in total; past that it raises
374
+ `UpstreamError` with status 504. `timeout_ms` can only shorten that, so values
375
+ above about 25000 have no effect.
376
+
307
377
  ---
308
378
 
309
379
  ## What goes in a payload?
310
380
 
311
- Every call is `fabric.<tool>(**keyword_arguments)`. There is no envelope to build
312
- and no request object to construct — the keywords *are* the payload.
381
+ Every call is `fabric.<tool>(...)` with the tool's arguments. There is no envelope
382
+ to build and no request object to construct — the arguments *are* the payload.
313
383
 
314
384
  ```python
315
385
  fabric.query_context(query="MATCH (n) WHERE n.project_id = $project_id RETURN n")
316
386
  # └──────────── this is the whole payload ────────────┘
317
387
  ```
318
388
 
389
+ Each method has a real signature generated from the tool's input schema, so your
390
+ editor lists the arguments and `help(fabric.save_context)` describes each one. The
391
+ first required argument may be passed by position — `fabric.get_execution("ex_1")`
392
+ — and the rest by name. A misspelt name is refused before anything is sent:
393
+
394
+ ```text
395
+ TypeError: get_execution() got an unknown argument 'exec_id'.
396
+ Did you mean 'execution_id'?
397
+ ```
398
+
399
+ To send a field the SDK does not list yet, use `fabric.call("get-execution", ...)`,
400
+ which forwards any keyword unchanged.
401
+
319
402
  ### You supply the intent; the server supplies the identity
320
403
 
321
404
  Some arguments are **server-owned**. They describe *who is calling*, and the
@@ -434,6 +517,61 @@ the ingestion path instead — see [Project mode](#project-mode-decides-your-ing
434
517
 
435
518
  Needs `fabric:ontology.write`.
436
519
 
520
+ #### Check what was written
521
+
522
+ `save_context` raises only when nodes were sent and none was written. When some
523
+ items were written and others were not, it returns normally — and so does a
524
+ batch of only relationships, even when none of them was written:
525
+
526
+ ```python
527
+ out = fabric.save_context(nodes=nodes, relationships=relationships)
528
+ if not out["success"]:
529
+ # e.g. ["relationship[3] (ISSUED_TO): endpoint node(s) not found"]
530
+ log.warning("partial save: %s nodes, %s relationships; %s",
531
+ out["nodes_merged"], out["relationships_merged"], out.get("errors"))
532
+ ```
533
+
534
+ | Field | Meaning |
535
+ |---|---|
536
+ | `success` | `True` only when every node and relationship sent was written |
537
+ | `nodes_merged` | Nodes written (created or updated) |
538
+ | `relationships_merged` | Relationships written (created or updated) |
539
+ | `errors` | One message per item left out, naming it as `node[i]` or `relationship[i]`; absent when there are none |
540
+ | `ontology_extended` | A label or relationship type new to this project was added |
541
+ | `new_labels`, `new_rel_types` | Which ones |
542
+
543
+ What lands in `errors` rather than raising:
544
+
545
+ - **A relationship whose `from` or `to` node does not exist** —
546
+ `endpoint node(s) not found`. Endpoints are looked up, never created: send the
547
+ nodes in the same call or an earlier one.
548
+ - **A batch write that failed on the server** — `not confirmed written … re-sending
549
+ the save is safe`.
550
+ - **A node whose access scope cannot be worked out**, when the project has scope
551
+ tagging on.
552
+
553
+ A merge key (`key`, `from.key` or `to.key`) must start with a letter followed
554
+ only by letters, digits and underscores (`order_id`, not `order-id` or
555
+ `order id`). Any other key raises `ValidationError` (422) for the whole call before anything is
556
+ written, naming the item, e.g. `node[1] (Order): invalid merge key "my-key"`.
557
+
558
+ **Batch size.** At most 10,000 nodes + relationships per call; more raises
559
+ `ValidationError` with `status == 413`. A call has about 25 seconds;
560
+ a few thousand items per call is a comfortable size.
561
+
562
+ **Timeouts.** A call that runs past ~25 seconds raises `UpstreamError` with
563
+ `status == 504` (not `TimeoutError_`: the gateway reports it as an execute
564
+ failure). It may have written none, part or all of the batch — writing stops at
565
+ the timeout, but a batch already running on the server can still land. Re-send
566
+ the same batch: every write is an idempotent MERGE, so re-sending — after a
567
+ timeout, or to retry the items in `errors` — never duplicates anything. A
568
+ re-send can time out again: the server checks every relationship type that is
569
+ new to the project before writing anything, and that check is slow on a large
570
+ graph. If it does, split the batch into smaller calls with fewer new
571
+ relationship types in each. If you
572
+ passed an `idempotency_key`, re-send with a new key (or none): the timed-out key
573
+ answers 409 "outcome unknown" and is never run again.
574
+
437
575
  ### Run an agent or a process flow
438
576
 
439
577
  These start real work and return without waiting for it.
@@ -458,6 +596,33 @@ the execution id off `run` rather than assuming a field name.
458
596
  `run_process_flow`, which does *not* accept `fabric:orchestrate.write` in its
459
597
  place.
460
598
 
599
+ ### Restart, pause and resume a run
600
+
601
+ A run that failed, finished with a wrong result, paused or stopped for anomaly
602
+ review does not have to start over. `restart_execution` re-runs it, the same as
603
+ **Restart** in the console: from `agent_id`, keeping the work of the agents
604
+ before it, or from the first agent when `agent_id` is omitted. Only a run that is
605
+ `paused`, `failed`, `completed` or `anomaly_detected` can be restarted.
606
+
607
+ ```python
608
+ again = fabric.restart_execution(run_id) # from the first agent
609
+ again = fabric.restart_execution(run_id, agent_id="66f…") # from that agent
610
+ status = fabric.get_execution(execution_id=again["execution_id"])
611
+ ```
612
+
613
+ A restart is a new run: poll the returned `execution_id`, and `restarted_from`
614
+ names the run it came from. `agent_id` is an agent `_id` of the run's own process
615
+ flow; one that is not in it raises `NotFound` and lists the run's agents. A run
616
+ in another state raises `ConflictError`; a run in another project, or one someone
617
+ else started, raises `NotFound`. Restarting a run awaiting anomaly review cancels
618
+ it and starts the new one.
619
+
620
+ `pause_execution(run_id)` pauses a `running` or `ready` run and
621
+ `resume_execution(run_id)` carries a `paused` run on under the same id. All three
622
+ need `fabric:agent.run`. `restart_execution` and `resume_execution` start work, so
623
+ like `run_process_flow` they are held for approval when the project's write gate
624
+ is on; `pause_execution` stops work and is never held.
625
+
461
626
  ### Choose which model your agents use
462
627
 
463
628
  Every agent has an `llm.model`. When you create an agent without one, it is
@@ -480,9 +645,11 @@ models = fabric.list_models()
480
645
 
481
646
  ```
482
647
  {'registry': [{'id': 'mdl_bx_nova', 'name': 'Nova Pro', 'provider': 'bedrock',
483
- 'health': 'healthy', 'default': True},
648
+ 'health': 'healthy', 'default': True,
649
+ 'cost_per_1m': 0.8, 'cost_label': '$0.80 / 1M'},
484
650
  {'id': 'mdl_ol_qwen', 'name': 'Qwen 2.5', 'provider': 'ollama',
485
- 'health': 'healthy', 'default': False}],
651
+ 'health': 'healthy', 'default': False,
652
+ 'cost_per_1m': None, 'cost_label': 'compute'}],
486
653
  'available': [{'model_name': 'system_model', 'label_name': 'WEXA System Model'},
487
654
  {'model_name': 'My-Azure#azure#org_7f2a#gpt-4o',
488
655
  'label_name': 'My Azure gpt 4o'}],
@@ -552,14 +719,48 @@ answer = fabric.run_model(model="mdl_bx_nova", prompt="Summarize Q3 in one line.
552
719
  ```
553
720
  {'output': 'Revenue grew 12% on flat headcount.',
554
721
  'model': 'mdl_bx_nova', 'source': 'requested',
555
- 'tokens': 84, 'cost_usd': 0.000252, 'latency_ms': 940}
722
+ 'tokens': 84, 'input_tokens': 61, 'output_tokens': 23,
723
+ 'cached_input_tokens': 0, 'cost_usd': 0.0000672, 'latency_ms': 940}
556
724
  ```
557
725
 
726
+ `tokens` is the total. `input_tokens` and `output_tokens` are the provider's split
727
+ of it, so you can see where tokens go and price a call yourself, since input and
728
+ output are priced differently. They usually add up to `tokens`; a provider that
729
+ counts reasoning tokens apart from both will not. Both are `None` when the
730
+ provider reported no split — you get `None`, never a guess. A gateway older than
731
+ the split omits all three token fields, so read them with `.get()`.
732
+
733
+ `cached_input_tokens` is the part of `input_tokens` the provider served from its
734
+ prompt cache, usually at a lower price. `0` means the provider reported that none
735
+ were cached; `None` means it does not report a cache figure, so you cannot tell.
736
+
558
737
  `model` in the result is the model that **actually ran**, and `source` says why
559
738
  it was chosen — `requested`, `organization default` or `platform default`. Read
560
739
  them before attributing a charge: they are what makes an unexpected bill
561
740
  traceable.
562
741
 
742
+ #### What `cost_usd` is
743
+
744
+ `cost_usd` is an **estimate for comparing runs, not what you are billed.**
745
+
746
+ - For a model with a stored price, it is `tokens × cost_per_1m ÷ 1,000,000`. One
747
+ price covers input and output tokens alike, so a long answer is not costed
748
+ higher than a long prompt. `list_models` returns that price as `cost_per_1m` on
749
+ each `registry` entry. In the example above, 84 tokens on Nova Pro at $0.80 per
750
+ 1M is $0.0000672.
751
+ - For a model with no stored price (`cost_per_1m` is `None`, for example
752
+ GPT-OSS), it is the model gateway's own reported cost, or `0` when the gateway
753
+ reports none.
754
+ - Credits are charged by a separate calculation, so the credits a call consumes
755
+ will not match `cost_usd`. Do not budget or bill on `cost_usd`.
756
+
757
+ #### Checking your usage
758
+
759
+ The SDK has no call that reads usage or credit charges, and an API key cannot
760
+ read them. Usage is only visible in the Fabric console: log in and open
761
+ `/settings/usage` for credits by project, model, agent and user, plus a table of
762
+ calls. There is no per-API-key breakdown.
763
+
563
764
  ```python
564
765
  answer = fabric.run_model(prompt="Summarize Q3 in one line.")
565
766
  if answer["source"] != "requested":
@@ -605,16 +806,47 @@ These are the controls you may set. They are an allow-list, not a pass-through:
605
806
 
606
807
  | Field | What it does |
607
808
  | ----------------- | ------------------------------------------------------- |
608
- | `max_tokens` | Ceiling on the tokens generated. Defaults to 512. |
809
+ | `max_tokens` | Ceiling on the tokens generated. Defaults to 512. On a thinking model it includes the reasoning. |
609
810
  | `temperature` | 0 to 2. Defaults to 0.2. |
610
811
  | `top_p` | Nucleus sampling, 0 to 1. |
611
812
  | `stop` | Up to four sequences that end generation. |
612
813
  | `seed` | Best-effort determinism, where the provider supports it. |
613
814
  | `response_format` | e.g. `{"type": "json_object"}`. |
815
+ | `reasoning_effort` | `none`, `minimal`, `low`, `medium`, `high` or `xhigh`. How much a thinking model may reason. |
614
816
 
615
817
  An out-of-range value is **refused, not clamped** — you never silently get a call
616
818
  you did not ask for.
617
819
 
820
+ An argument `run_model` does not support is **refused, not ignored**: a misspelt
821
+ `max_token` fails with `S4:validate-input` instead of quietly running at the
822
+ default budget.
823
+
824
+ #### Thinking models and `max_tokens`
825
+
826
+ On a thinking model (Gemini 2.5 and later, Claude Sonnet and Opus 4, Qwen3 and
827
+ similar) the **reasoning tokens count against `max_tokens`**, alongside the
828
+ answer, and they are included in `tokens` and `cost_usd`. A model that reasons
829
+ past the whole budget returns an empty or cut-off answer, which is most likely at
830
+ the default of 512 on a hard prompt.
831
+
832
+ `reasoning_effort` controls it. Leave it out and Fabric asks for the lowest level
833
+ the model accepts (`none` on most models, `low` on Gemini 3.7 and later, nothing
834
+ on GPT-OSS). That is a floor, not a guarantee: on a hard prompt a model reasons
835
+ anyway. To let a model think a problem through, raise both:
836
+
837
+ ```python
838
+ answer = fabric.run_model(
839
+ prompt="Plan the migration in five steps.",
840
+ reasoning_effort="high",
841
+ max_tokens=8192,
842
+ )
843
+ ```
844
+
845
+ The level is sent to the model as given. A level the model does not support
846
+ (Gemini 3.7 and later refuse `none` and `minimal`, GPT-OSS refuses `none`) comes
847
+ back as `S8:model-invalid-parameters` with the provider's own message. Fabric
848
+ does not swap in a different level.
849
+
618
850
  You may **not** set an `endpoint`, `api_base`, `api_version`, `secret_ref`,
619
851
  `api_key`, `provider` or `extra_params`. Fabric fills those from the model's own
620
852
  registry entry, and `run_model` raises `ValidationError` before any request is
@@ -653,6 +885,155 @@ cannot report when its data is all in, so `ingestion` stays `"running"` while da
653
885
  `"not_supported"` means the connector has nothing to pull. You can sync only a connector
654
886
  provisioned in your project, and starting a sync needs `fabric:connector.sync`.
655
887
 
888
+ ### Post to Slack through a connector
889
+
890
+ There is no Slack method in the SDK. Every connector action, such as posting a Slack
891
+ message, runs through `run_connector_action`, and your code looks up the connector and the
892
+ action's arguments at run time. It takes three steps:
893
+
894
+ ```python
895
+ from wexa import ApprovalRequired
896
+
897
+ # 1. Find the connector. list_connectors() returns the connectors this project may use;
898
+ # one still waiting for its credentials is listed with no actions, so skip it.
899
+ connectors = fabric.list_connectors()["connectors"]
900
+ slack = next(c for c in connectors if c["category"] == "slack" and c["actions"])
901
+ connector_id = slack["connector_id"]
902
+
903
+ # 2. Find the action and read its arguments. input_schema is a JSON Schema.
904
+ action = next(a for a in slack["actions"] if a["name"] == "post_message")
905
+ action["input_schema"]["required"] # ['channel']
906
+ action["input_schema"]["properties"] # channel, text, thread_ts, blocks, as_bot, ...
907
+
908
+ # 3. Run it. Connector actions are consequential, so handle ApprovalRequired.
909
+ try:
910
+ sent = fabric.run_connector_action(
911
+ connector_id=connector_id,
912
+ action="post_message",
913
+ params={"channel": "C0123456789", "text": "Refund issued for order 1042"},
914
+ )
915
+ sent["data"]["ts"] # the message's Slack timestamp
916
+ except ApprovalRequired as e:
917
+ token = e.resume_token # keep it; resume once a person approves
918
+ ```
919
+
920
+ `channel` takes a channel ID, a channel name, or a user ID (`U…` or `W…`) to send a direct
921
+ message. `text` is required unless you send `blocks` or `attachments`. The message is posted
922
+ **as the Slack user the connector was configured with**. Add `"as_bot": True` to `params` to
923
+ post as the Slack app instead.
924
+
925
+ After the approval, resume with the token: `fabric.run_connector_action(
926
+ connector_id=connector_id, action="post_message", resume_token=token)`. Only the token is sent; it stands for the call you
927
+ made, so the other arguments are not sent again. Or pass `wait_for_approval=True` to the first
928
+ call and it waits for the decision itself (see [Approvals](#approvals)).
929
+
930
+ Running an action needs `fabric:connector.run`, and a connector outside your access scope is
931
+ refused. `list_connectors` lists only connectors provisioned for you. To plan against Slack
932
+ before it is provisioned, read its actions and their fields from the catalog, then ask
933
+ for it with `request_connector`:
934
+
935
+ ```python
936
+ catalog = fabric.list_connector_catalog(category="slack", schemas=True)
937
+ ```
938
+
939
+ `list_connector_catalog` is in the SDK from 0.6.0.
940
+
941
+ ### Connect a data source (Snowflake, databases, warehouses)
942
+
943
+ The console's **Data Sources** tab lists sources whose data is ingested into the graph
944
+ (Snowflake, Postgres, MongoDB and more). They are not in `list_connector_catalog`, which lists
945
+ connectors that have actions. Three calls do what the wizard does:
946
+
947
+ ```python
948
+ # 1. The cards: categories with their service types. `search` narrows them.
949
+ catalog = fabric.list_om_catalog(search="snow")
950
+
951
+ # 2. One source's form: fields (nested ones have dotted ids such as authType.password),
952
+ # required_fields, secret_fields, defaults, and the metadata filters.
953
+ form = fabric.get_om_connection_form(service_type="Snowflake")
954
+
955
+ # 3. Connect it. om_connection takes the place of credentials; the category is the
956
+ # service type in lower case (form["category"]). Admins only.
957
+ created = fabric.configure_connector(
958
+ category=form["category"], name="Warehouse",
959
+ om_connection={"account": "acme-xy12345", "username": "svc", "authType.password": pw},
960
+ filters={"databaseFilterPattern": {"includes": ["SALES"]}}, # optional
961
+ )
962
+ ```
963
+
964
+ Fabric sends the same body the console does: your values (dotted ids nested), the defaults the
965
+ form lists, and the filters. Every password, key and token in `om_connection` is masked in
966
+ Fabric's logs and errors and never returned, as `credentials` are. A data source's connection
967
+ cannot be changed with `connector_id`: `delete_connector` it and connect it again. After
968
+ connecting, `sync_connector(connector_id=..., wait=True)`, `get_connector_ingestion` and
969
+ `query_context` work as for any connector. `examples/om_connector_journey.py` runs the whole path.
970
+
971
+ Known limits: a project's second connector of the same category (two Snowflake accounts) cannot
972
+ be synced (`sync_connector` answers 422), because the platform's sync matches the first connector
973
+ of a category only. `sync_connector` takes no `max_rows` or `tables` yet: limiting an ingest needs
974
+ a change in the harness service.
975
+
976
+ ### Connect WhatsApp
977
+
978
+ `connect_whatsapp` does what adding the WhatsApp connector does in the console. It creates
979
+ the connector and answers with its `connector_id`. While the number is not linked yet,
980
+ `status` is `"pending"` and `connect_url` is a page with a QR code: scan it with WhatsApp on
981
+ the phone (Settings > Linked devices > Link a device) within 10 minutes. A number that is
982
+ already linked comes back `"ready"` with `connected: True` and no link.
983
+
984
+ ```python
985
+ state = fabric.connect_whatsapp(
986
+ name="Support WhatsApp",
987
+ phone_number="919876543210", # country code and number, no + or spaces
988
+ email_id="you@example.com", # the PIN is sent here
989
+ pin="1234", # with the email, proves the number is yours
990
+ )
991
+ state["connect_url"] # open it and scan the QR code
992
+ ```
993
+
994
+ After the scan, `complete_whatsapp_connection` finishes the connection, the same as
995
+ **Finish authentication** in the console. It asks WhatsApp's provider for the account:
996
+ when the scan worked, the connector becomes `"ready"` and `connected` is `True`. When it
997
+ did not, because the link expired, the scan failed or nobody scanned, the connector stays
998
+ `"pending"` and you get a new `connect_url`. Calling it on a connected connector changes
999
+ nothing. `get_whatsapp_connection` reads the status without changing anything.
1000
+
1001
+ ```python
1002
+ state = fabric.complete_whatsapp_connection(connector_id=state["connector_id"])
1003
+ state["connected"] # True once the account is linked
1004
+ state["next_step"] # what to do next, in words
1005
+ ```
1006
+
1007
+ Pass `wait=True` to either call to wait for the scan: it polls `get_whatsapp_connection`
1008
+ every `poll` seconds (default 5) until the account is connected. At `wait_timeout`
1009
+ (default 600, the link's lifetime) it calls `complete_whatsapp_connection` once and
1010
+ returns that answer, so a scan whose provider callback never arrived is still picked up,
1011
+ and an abandoned link is replaced. Nothing is raised at the limit; check `connected`.
1012
+
1013
+ A request the platform refuses raises `ValidationError` with the platform's own reason,
1014
+ the same one the console shows: `"Invalid phone number format"`, or the email and PIN not
1015
+ matching an earlier registration of the number. A provider that rejects the link request
1016
+ raises `UpstreamError`. Connecting needs `fabric:connector.connect`; reading the status
1017
+ needs `fabric:orchestrate.read`. `examples/whatsapp_connect.py` is the whole flow.
1018
+
1019
+ ### Register a peer agent (an external agent)
1020
+
1021
+ ```python
1022
+ fabric.handshake_peer_agent(endpoint="https://agents.example.com/a2a", protocol="a2a", secret=token)
1023
+ reg = fabric.register_peer_agent(name="invoice-reconciler", endpoint="https://agents.example.com/a2a",
1024
+ protocol="a2a", secret=token)
1025
+ ```
1026
+
1027
+ When `secret` is set, Fabric sends it as `Authorization: Bearer <secret>` on every call to the
1028
+ external agent. With no secret, no header is sent. Only `auth="key"` (the default) works;
1029
+ `oauth` and `mtls` are refused. Fabric does not fetch or refresh tokens, so a short-lived
1030
+ token stops working when it expires.
1031
+
1032
+ There is no call that updates a secret. To rotate one: register a new connection, point every
1033
+ `interop_agent` node at the new connection id with `update_process_flow` (`registration_id`),
1034
+ then call `delete_peer_agent` on the old one. `delete_peer_agent` refuses while a node still
1035
+ uses the connection.
1036
+
656
1037
  ### Search code
657
1038
 
658
1039
  ```python
@@ -695,46 +1076,43 @@ everything you need to finish the call later.
695
1076
 
696
1077
  ### What gates
697
1078
 
698
- Two things gate a call: a **consequential write made with an API key or an SDK
699
- session** (see below), and **the data you touch**. On the data side there is no
700
- amount threshold. A call gates when:
1079
+ Four policy rules can hold a call. The rule that held yours is on the error:
1080
+ `e.rule` is its name and `e.reason` says why.
701
1081
 
702
- - any graph label or argument it touches contains `pii`, `sensitive`,
703
- `confidential` or `personal` — substring match, case-insensitive; or
704
- - the asset it touches is classified restricted in OpenMetadata.
705
-
706
- So `save_context` with a node label of `Refund` runs straight through, and the
707
- same call with a label of `CustomerPersonalData` comes back as an approval. On
708
- an auto-mode project this gates **everyone, admins included**.
1082
+ | `e.rule` | Held when |
1083
+ |---|---|
1084
+ | `consequential write requires approval for SDK callers` | The project's consequential write gate is on and the call is a consequential write made with an API key or an SDK session (admin keys included). |
1085
+ | `om-pii-classification gate` | The call touches an asset OpenMetadata has classified PII or Sensitive. Words such as "personal" or "pii" in a goal, prompt, label or query do **not** gate; only the classification does. An admin in a non-automated call is let through with an audit entry. |
1086
+ | `ontology commit requires gate` | A non-admin `create_ontology(mode="commit")` on an Advanced/manual project. |
1087
+ | `connector action requires approval` | A connector action the platform does not mark safe. |
709
1088
 
710
- The second gate site is narrow: a non-admin `create_ontology(mode="commit")`,
711
- and only on an Advanced/manual project.
1089
+ `e.message` is the tool's own description of the action and differs per tool, so
1090
+ branch on `e.rule`, not on the text. Both are `None` against a server that does
1091
+ not send them.
712
1092
 
713
- Reads are not exempt for being reads — a `query_context` whose Cypher mentions
714
- a `Personal` label gates too.
1093
+ Reads are not exempt for being reads: a `query_context` that touches a
1094
+ classified asset gates too.
715
1095
 
716
- ### Consequential writes wait for approval by default
1096
+ ### Consequential writes wait for approval when the gate is on
717
1097
 
718
- **Breaking change.** Every project now holds consequential writes made with an
719
- API key or an SDK session until a person approves them. This is on by default,
720
- and it applies to admin API keys too. Actions taken by a person in the console
721
- are not held.
1098
+ The consequential write gate is **off by default**. A project admin turns it on,
1099
+ or back off, in the project's settings. While it is on, consequential writes made
1100
+ with an API key or an SDK session wait for a person to approve them, and that
1101
+ includes admin API keys. Actions taken by a person in the console are not held.
1102
+ `docs("governance")` reports the same default.
722
1103
 
723
1104
  Consequential writes include table row inserts and updates (`insert_table_rows`,
724
1105
  `update_table_row`), table create and rename (`create_table`, `rename_table`),
725
1106
  trigger changes (`set_triggers`) and connector actions (`run_connector_action`),
726
1107
  as well as the tools that were already consequential, such as
727
- `delete_table_rows`, `save_context` and `run_agent`. Each of these calls now
728
- raises `ApprovalRequired` unless the project has the gate turned off.
1108
+ `delete_table_rows`, `save_context` and `run_agent`. With the gate on, each of
1109
+ these raises `ApprovalRequired`. With it off, they run without approval. The
1110
+ data-driven gating above applies either way.
729
1111
 
730
- A project admin turns the gate off, or back on, in the project's settings. With
731
- it off, consequential writes from API keys and SDK sessions run without approval
732
- again. The data-driven gating above still applies either way.
733
-
734
- Because the data is one of the triggers, **handle `ApprovalRequired` on every governed
735
- call**, not on the one step you expect to gate. Classification is populated at
736
- runtime, so a call that sailed through yesterday can start gating today with no
737
- change on your side.
1112
+ **Handle `ApprovalRequired` on every governed call**, not on the one step you
1113
+ expect to gate. A project admin can turn the write gate on at any time, and
1114
+ classification is populated at runtime, so a call that sailed through yesterday
1115
+ can start gating today with no change on your side.
738
1116
 
739
1117
  ### The complete round trip
740
1118
 
@@ -747,22 +1125,25 @@ from wexa import Fabric, ApprovalRequired
747
1125
 
748
1126
  fabric = Fabric()
749
1127
 
750
- # 1. The call gates. HTTP 202, no result — an ApprovalRequired instead.
1128
+ # 1. The call is held. HTTP 202, no result — an ApprovalRequired instead.
751
1129
  try:
752
1130
  fabric.save_context(nodes=[
753
- {"label": "CustomerPersonalData", "key": "id",
1131
+ {"label": "Customer", "key": "id",
754
1132
  "properties": {"id": "cust_8841", "email": "ada@example.com"}},
755
1133
  ])
756
1134
  except ApprovalRequired as e:
757
1135
  print(e.approval_id) # apr_000012
758
1136
  print(e.resume_token) # rtok_000012_17... single use, keep it safe
759
1137
  print(e.lifecycle_id) # the lifecycle that parked
1138
+ print(e.rule) # consequential write requires approval for SDK callers
1139
+ print(e.reason) # why that rule held it
760
1140
  token = e.resume_token
761
1141
  ```
762
1142
 
763
1143
  ```python
764
- # 2. A human decides. The deciding credential must hold an admin role —
765
- # OWNER / ORG_ADMIN / PROJECT_ADMIN. Usually it happens in the console.
1144
+ # 2. A human decides, usually in the console's Approvals Inbox. The registry
1145
+ # decides who may: a project admin of the approval's project, or someone
1146
+ # above them in the organization.
766
1147
  admin = Fabric(api_key="fab_sk_admin_...")
767
1148
  [a for a in admin.approvals("pending")]
768
1149
  # [{'id': 'apr_000012', 'tool': 'save-context', 'what': '...',
@@ -770,133 +1151,94 @@ admin = Fabric(api_key="fab_sk_admin_...")
770
1151
  admin.approve("apr_000012")
771
1152
  ```
772
1153
 
773
- A non-admin credential calling `approve()` gets
774
- `ForbiddenError: approver must be an admin role` (HTTP 403).
775
-
776
- **An admin cannot approve their own request either.** `approve()` compares
777
- `decided_by` to `requested_by` and refuses a match with
778
- `ConflictError: an approval cannot be decided by the user who requested it`.
779
- Since an API key carries its creator's user id, the key that triggered a gated
780
- call can never clear it — a second admin must. In a project with only one
781
- admin that makes a gated call unsatisfiable, so the deployment can set
782
- `ALLOW_SELF_APPROVAL=true`, which permits it and still records the requester in
783
- `decided_by` so the audit ledger shows it was self-approved.
784
-
785
- ```python
786
- # 3. Your code resumes. Send ONLY the token — the engine substitutes the
787
- # approved arguments, so anything else you pass is ignored.
788
- result = fabric.save_context(resume_token=token)
789
- print(result) # the write landed
790
- print(result.lifecycle_id)
791
- ```
1154
+ `reject()` needs a reason: `admin.reject("apr_000012", "not this quarter")`. Without
1155
+ one it raises `ValidationError` before any request is sent.
792
1156
 
793
- The resume must come from the **same user and project** that requested it. An
794
- admin cannot resume on your behalf, and the approved arguments win — you cannot
795
- amend a call at approval time.
1157
+ A credential that may not decide the approval gets `ForbiddenError` (HTTP 403).
1158
+ The rule is the registry's, the same one the console Inbox applies, so the SDK and
1159
+ the console never disagree about who may approve. The approver is always taken
1160
+ from your credential: a request body naming one is refused.
796
1161
 
797
- An approval has a deadline set by its risk. Past the deadline it becomes
798
- `overdue`, and it stays open for a person to decide. At twice the deadline it
799
- becomes `expired`, can no longer be decided, and the token is dead.
1162
+ Whoever may decide an approval may also decide one they raised themselves:
1163
+ self-approval is not blocked, and there is no setting that blocks it. When the
1164
+ approver is the requester, the decision still goes through, and it is recorded
1165
+ with `self_approved` set in the audit log so a reviewer can see it afterwards. If
1166
+ you need a second person to sign off, enforce that in your own workflow.
800
1167
 
801
- ### Blocking instead of handling it yourself
1168
+ ### Ask for an approval from your app
802
1169
 
803
- If your process can afford to sit and wait, opt in and the client polls for you:
1170
+ `request_approval` puts your app's own decision in front of a person in this
1171
+ project. It shows in the Fabric Approvals Inbox as an **App request**, beside every
1172
+ other approval, and a project admin decides it there.
804
1173
 
805
1174
  ```python
806
- result = fabric.save_context(
807
- nodes=[{"label": "CustomerPersonalData", "key": "id", "properties": {...}}],
808
- wait_for_approval=True,
809
- approval_timeout=600, # seconds; raises ApprovalError past this
810
- poll=5, # seconds between checks
1175
+ req = fabric.request_approval(
1176
+ "Refund order 1042",
1177
+ "refund-1042",
1178
+ reason="Customer was charged twice",
1179
+ risk="high",
1180
+ payload={"order": "1042", "amount": 129.0},
811
1181
  )
1182
+ print(req["id"], req["status"]) # ar_... pending
812
1183
  ```
813
1184
 
814
- This does the whole round trip: gate, poll `approvals()`, resume with the token.
815
-
816
- The wait ends on the first final status of that approval. `approved` resumes the
817
- call. `rejected`, `expired`, `overdue` and `consumed` raise `ApprovalError` with
818
- the status in the message (`approval rejected`) and the approval in `e.raw`. An
819
- `overdue` approval can still be approved in the console; to keep waiting for it,
820
- checkpoint the token as below and resume later.
1185
+ `reference` is your app's own id for the request. Calling again with the same
1186
+ reference while the approval is open returns that approval rather than a second
1187
+ one; once it is decided, the same reference opens a new approval. `risk` sets the
1188
+ deadline: `high` 24 hours, `medium` (the default) 48, `low` 72. `expires_at` is
1189
+ that deadline, after which the approval is `overdue`; `hard_expires_at` is when it
1190
+ expires. The organization, project and requester come from your credential.
821
1191
 
822
- ### Resuming from a durable pipeline
823
-
824
- `wait_for_approval=True` blocks in-process, so a crash or a deploy while a human
825
- is deliberating loses an approval that was actually granted. If that matters,
826
- checkpoint the token before you block, and resume later — possibly from another
827
- process:
1192
+ Read the decision with `get_approval`:
828
1193
 
829
1194
  ```python
830
- try:
831
- fabric.save_context(nodes=[...])
832
- except ApprovalRequired as e:
833
- checkpoint(e.approval_id, e.resume_token) # durable, before you wait
834
-
835
- # ... minutes or hours later, a different process ...
836
- fabric.save_context(resume_token=load_token(), retry=True)
837
- ```
838
-
839
- Passing `resume_token=` takes exactly the same code path as
840
- `wait_for_approval`, so everything below behaves identically either way.
841
-
842
- ### A failed resume is not always safe to retry
843
-
844
- The token is single-use, and the gateway redeems it **partway** through the
845
- lifecycle:
846
-
847
- ```
848
- S2 scope → S3 quota → REDEEM TOKEN → S4 validate → S5 policy → S8 execute
1195
+ a = fabric.get_approval(req["id"])
1196
+ a["status"], a.get("decided_by"), a.get("decision_reason"), a.get("choice")
849
1197
  ```
850
1198
 
851
- A refusal before redemption leaves the token intact. A refusal after redemption
852
- has burned it: the write did not land, and re-running needs a *new* human
853
- approval. Every exception carries `resume_spent` to tell the two apart.
1199
+ Or wait for it:
854
1200
 
855
1201
  ```python
856
- from wexa import WexaError
1202
+ from wexa import ApprovalError
857
1203
 
858
1204
  try:
859
- fabric.save_context(resume_token=token, retry=True)
860
- except WexaError as e:
861
- if e.resume_spent:
862
- alert_human(e.lifecycle_id) # approval consumed, write did NOT land
863
- else:
864
- pass # nothing consumed, safe to re-run as-is
1205
+ a = fabric.request_approval("Refund order 1042", "refund-1042",
1206
+ wait=True, timeout=3600, poll=10)
1207
+ issue_refund()
1208
+ except ApprovalError as e:
1209
+ print(e) # approval rejected
865
1210
  ```
866
1211
 
867
- | Refusal on resume | Stage | `resume_spent` | What to do |
868
- |---|---|---|---|
869
- | `QuotaExceeded` (429) | S3, before redemption | `False` | Re-send the same token |
870
- | `ValidationError` (400/422) | S4, after redemption | `True` | Needs a new approval |
871
- | `PolicyDenied` (403) | S5, after redemption | `True` | Needs a new approval |
872
- | `UpstreamError` (502) | S8, after redemption | `True` | Needs a new approval |
873
-
874
- `retry=True` covers the resume, but only for `QuotaExceeded` — the one stage
875
- that refuses before redemption. Retrying anything later would re-send a spent
876
- token and earn a misleading `ApprovalError: resume rejected: approval not
877
- found`, burying the real error. Replaying a token you already spent gets you
878
- that same message.
1212
+ With `wait=True` the client polls `get_approval` and stops on the first final
1213
+ status, with the same rule as `wait_for_approval`: `approved` returns the approval;
1214
+ `rejected`, `expired` and `overdue` raise `ApprovalError` with the status in the
1215
+ message and the approval in `e.raw`. Past `timeout` seconds (default 600) it raises
1216
+ `ApprovalError` too, and the approval stays open for you to read later.
879
1217
 
880
- ---
1218
+ `choices=["ship", "hold"]` asks the approver to pick one; the pick comes back as
1219
+ `choice`. In the Inbox each choice approves with that pick, in place of Approve and
1220
+ Reject, so the status is `approved` whichever was picked: act on `choice`, and include
1221
+ an option such as `hold` when the approver needs a way to say no.
881
1222
 
882
1223
  ## Reference
883
1224
 
884
1225
  ### Methods
885
1226
 
886
- Sixty tools, plus five governance calls that need no grant.
1227
+ Sixty-four tools, plus five governance calls that need no grant.
887
1228
 
888
1229
  | Area | Methods | Grant |
889
1230
  |---|---|---|
890
- | Graph read | `query_context` | `fabric:query.read` |
1231
+ | Graph read | `query_context`, `graph_stats`, `graph_subgraph` | `fabric:query.read` |
891
1232
  | Graph write | `save_context`, `create_ontology`, `delete_context` | `fabric:ontology.write` |
892
1233
  | Code | `search_code`, `fetch_code` | `fabric:query.read` |
893
1234
  | Docs | `docs` | `fabric:docs.read` |
894
1235
  | Connectors | `connector_read` | `fabric:query.read` |
895
1236
  | Connector provisioning | `provision_connector` | `fabric:skill.write` |
896
1237
  | Execution | `run_agent`, `run_process_flow` | `fabric:agent.run` |
1238
+ | Execution control — restart, pause, resume | `restart_execution`, `pause_execution`, `resume_execution` | `fabric:agent.run` |
897
1239
  | Agents — read | `list_agents`, `get_agent`, `agent_versions` | `fabric:orchestrate.read` |
898
1240
  | Agents — write | `create_agent`, `update_agent`, `delete_agent`, `rollback_agent_version` | `fabric:orchestrate.write` |
899
- | Process flows — read | `get_process_flow`, `get_execution`, `flow_versions` | `fabric:orchestrate.read` |
1241
+ | Process flows — read | `list_process_flows`, `get_process_flow`, `get_execution`, `flow_versions` | `fabric:orchestrate.read` |
900
1242
  | Process flows — write | `create_process_flow`, `update_process_flow`, `promote_flow`, `rollback_flow_version` | `fabric:orchestrate.write` |
901
1243
  | Process flows — delete | `delete_process_flow` | `fabric:flow.delete` |
902
1244
  | Knowledge base — read | `knowledge_base_retrieve` | `fabric:orchestrate.read` |
@@ -907,6 +1249,13 @@ Sixty tools, plus five governance calls that need no grant.
907
1249
  | Model calls | `run_model` | `fabric:model.run` |
908
1250
  | Connector actions — list, run | `list_connectors`, `run_connector_action` | `fabric:orchestrate.read`, `fabric:connector.run` |
909
1251
  | Connector sync — start or join, status | `sync_connector`, `get_connector_sync` | `fabric:connector.sync`, `fabric:orchestrate.read` |
1252
+ | Connectors — catalog, setup form, access scopes, ingestion | `list_connector_catalog`, `get_connector_form`, `list_connector_access_scopes`, `get_connector_ingestion` |
1253
+ | Data sources — catalogue, connection form | `list_om_catalog`, `get_om_connection_form` | `fabric:orchestrate.read` | `fabric:orchestrate.read` |
1254
+ | Connectors — configure with credentials, disconnect (admins only) | `configure_connector`, `delete_connector` | `fabric:skill.write` |
1255
+ | Connectors — request one for someone to configure (consequential) | `request_connector` | `fabric:skill.write` |
1256
+ | User-defined connectors — list, read | `list_user_connectors`, `get_user_connector` | `fabric:orchestrate.read` |
1257
+ | User-defined connectors — import a spec, save a draft, test an action, publish, delete (publish and delete consequential) | `import_connector_spec`, `save_user_connector`, `test_user_connector_action`, `publish_user_connector`, `delete_user_connector` | `fabric:skill.write` |
1258
+ | WhatsApp — connect, finish, status | `connect_whatsapp`, `complete_whatsapp_connection`, `get_whatsapp_connection` | `fabric:connector.connect`, `fabric:orchestrate.read` |
910
1259
  | Peer agent connections — read, handshake | `list_peer_agents`, `handshake_peer_agent` | `fabric:orchestrate.read` |
911
1260
  | Peer agent connections — register, remove | `register_peer_agent`, `delete_peer_agent` | `fabric:orchestrate.write` |
912
1261
  | Schedules — read | `list_schedules`, `get_schedule` | `fabric:orchestrate.read` |
@@ -915,7 +1264,8 @@ Sixty tools, plus five governance calls that need no grant.
915
1264
  | Triggers — write | `set_triggers` | `fabric:orchestrate.write` |
916
1265
  | Data Tables — read | `list_tables`, `get_table`, `query_table_rows` | `fabric:table.read` |
917
1266
  | Data Tables — write | `create_table`, `rename_table`, `delete_table`, `insert_table_rows`, `update_table_row`, `delete_table_rows`, `add_column`, `edit_column`, `delete_column` | `fabric:table.write` |
918
- | Governance | `whoami`, `approvals`, `approve`, `reject`, `lifecycle` | — |
1267
+ | Approvals from your app | `request_approval`, `get_approval` | — |
1268
+ | Governance | `whoami`, `approvals`, `approve`, `reject`, `lifecycle`, `policy_decisions` | — |
919
1269
  | SDK session | `Fabric.login`, `auth.refresh`, `auth.logout` | — |
920
1270
 
921
1271
  Three more grants exist for planes this client does not wrap:
@@ -1013,8 +1363,23 @@ except OSError: # never got there
1013
1363
 
1014
1364
  A **tool call** returns a `dict` subclass with the correlation ids attached
1015
1365
  rather than nested, so you can treat it as the payload and still trace it. The
1016
- governance methods (`whoami`, `approvals`, `approve`, `reject`, `lifecycle`)
1017
- return plain dicts and lists — no `.lifecycle_id` on those.
1366
+ governance methods (`whoami`, `approvals`, `approve`, `reject`, `lifecycle`,
1367
+ `policy_decisions`) return plain dicts and lists — no `.lifecycle_id` on those.
1368
+
1369
+ `policy_decisions(...)` reads the policy evaluations recorded for your project: what a key was
1370
+ allowed or denied, and what data was withheld from it. Filters are optional keywords (`tool`,
1371
+ `verdict`, `rule`, `subject`, `api_key_id`, `lifecycle_id`, `since`, `limit`):
1372
+
1373
+ ```python
1374
+ for d in fabric.policy_decisions(api_key_id="key_abc", limit=20):
1375
+ print(d["ts"], d["tool"], d["verdict"], d["rule"], d.get("api_key_id"))
1376
+ for x in d.get("denied", []):
1377
+ print(" withheld", x.get("label"), x.get("field"), x.get("requires"))
1378
+ ```
1379
+
1380
+ A key with its own data-access profile sees only its own decisions; an admin key sees the
1381
+ project's. Pass `explain_denials=True` to `query_context` to get the same list from a read, under
1382
+ `governance.denied`.
1018
1383
 
1019
1384
  ```python
1020
1385
  r = fabric.docs(topic="governance")
@@ -1204,15 +1569,9 @@ as unconfirmed.
1204
1569
  with `{approval_id, resume_token, lifecycle_id}`; the request appears in
1205
1570
  `approvals()`; `approve()` succeeds from an admin credential; the resume with
1206
1571
  only the token lands the write.
1207
- - Approving is gated on **role AND on being a different person**: a non-admin
1208
- credential gets `forbidden / "approver must be an admin role"`, and an admin
1209
- approving their own request gets `conflict / "an approval cannot be decided by
1210
- the user who requested it"`. `approval.decide()` compares `decided_by` to
1211
- `requested_by` and refuses a match, so this IS separation of duties. An API
1212
- key carries its creator's user id, which means the key that made the gated
1213
- call cannot clear it. Deployments with a single admin can set
1214
- `ALLOW_SELF_APPROVAL=true` to allow it; `decided_by` still records the
1215
- requester, so a self-approval stays visible in the ledger.
1572
+ - Who may approve is decided by the approval registry, the same rule the
1573
+ console Inbox applies: a credential that may not decide the approval gets
1574
+ `ForbiddenError`, and a request body naming the approver is refused.
1216
1575
  - Resume tokens are single-use. A resume that fails after redemption reports
1217
1576
  `resume_spent = True`, and replaying that token yields
1218
1577
  `ApprovalError: resume rejected: approval not found`.
@@ -1233,10 +1592,19 @@ Still source-derived only:
1233
1592
  ## Development
1234
1593
 
1235
1594
  ```bash
1236
- python3 wexa.py # offline self-check of the approval flow
1595
+ python3 -c "import wexa; wexa.demo()" # offline self-check of the approval flow
1596
+ python3 -m unittest discover -p 'test_*.py'
1237
1597
  WEXA_WORKSPACE=... WEXA_API_KEY=... python3 examples/status.py
1238
1598
  ```
1239
1599
 
1240
- `wexa.py`'s `demo()` covers the branches that actually have logic: the 202 →
1600
+ The tool methods in `wexa/_tools.py` are generated; do not edit them. When a
1601
+ gateway tool's `InputSchema()` changes:
1602
+
1603
+ ```bash
1604
+ (cd ../../api-gateway && go test ./internal/server -run TestSDKSchemaSnapshot -update-sdk-schema)
1605
+ python3 scripts/generate.py
1606
+ ```
1607
+
1608
+ `demo()` covers the branches that actually have logic: the 202 →
1241
1609
  approve → resume round trip, the resume retry boundary, tool routing, and the
1242
1610
  server-bound argument guard.