maigp-llamaindex 1.0.0__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.
@@ -0,0 +1,46 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ dist/
6
+ build/
7
+ .venv/
8
+ .eggs/
9
+
10
+ # Node
11
+ node_modules/
12
+ dist/
13
+
14
+ # Go
15
+ bin/
16
+
17
+ # Rust
18
+ target/
19
+
20
+ # .NET
21
+ bin/
22
+ obj/
23
+
24
+ # Java
25
+ *.class
26
+ out/
27
+
28
+ # IDE
29
+ .idea/
30
+ .vscode/
31
+ .kiro/
32
+ *.swp
33
+
34
+ # OS
35
+ .DS_Store
36
+ Thumbs.db
37
+
38
+ # Secrets (never commit)
39
+ .env
40
+ *.pem
41
+ *.key
42
+ *.pdf
43
+ BACKLOG/
44
+ patent/
45
+ docs/.archive/
46
+ review/
@@ -0,0 +1,6 @@
1
+ Metadata-Version: 2.4
2
+ Name: maigp-llamaindex
3
+ Version: 1.0.0
4
+ Summary: AIGP governance adapter for llamaindex
5
+ Requires-Python: >=3.11
6
+ Requires-Dist: maigp-agent-core>=1.0.0
@@ -0,0 +1,51 @@
1
+ """AIGP-LlamaIndex — Governed callback handler for LlamaIndex agents."""
2
+
3
+ __version__ = "1.0.0"
4
+
5
+ import asyncio
6
+ import time
7
+ from aigp_agent_core import AgentGovernance
8
+
9
+
10
+ class AigpCallbackHandler:
11
+ """LlamaIndex callback handler implementing AIGP governance.
12
+
13
+ Usage:
14
+ from llama_index.core import Settings
15
+ from aigp_llamaindex import AigpCallbackHandler
16
+
17
+ handler = AigpCallbackHandler(gov_url=..., app_id="my-rag-agent", hmac_secret=...)
18
+ Settings.callback_manager.add_handler(handler)
19
+ """
20
+
21
+ def __init__(self, gov_url: str, app_id: str, hmac_secret: str, **kwargs):
22
+ self._gov = AgentGovernance(gov_url, app_id, hmac_secret, **kwargs)
23
+ self._active = False
24
+
25
+ def on_event_start(self, event_type: str, payload: dict = None, **kwargs):
26
+ """LlamaIndex event start."""
27
+ if event_type == "query" and not self._active:
28
+ self._active = True
29
+ model_id = (payload or {}).get("model", "llamaindex")
30
+ self._gov.pre_invoke("query", model_id)
31
+
32
+ def on_event_end(self, event_type: str, payload: dict = None, **kwargs):
33
+ """LlamaIndex event end."""
34
+ if event_type == "llm" and payload:
35
+ usage = (payload or {}).get("usage", {})
36
+ self._gov.on_model_call(usage=usage)
37
+ elif event_type == "retrieve" and payload:
38
+ pass # Context retrieval — S7 logged in trace
39
+ elif event_type == "query" and self._active:
40
+ self._active = False
41
+ self._run_async(self._gov.post_invoke())
42
+
43
+ def on_error(self, error: Exception, **kwargs):
44
+ self._active = False
45
+ self._run_async(self._gov.on_error(error))
46
+
47
+ def _run_async(self, coro):
48
+ try:
49
+ asyncio.get_event_loop().run_until_complete(coro)
50
+ except RuntimeError:
51
+ asyncio.run(coro)
@@ -0,0 +1,13 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "maigp-llamaindex"
7
+ version = "1.0.0"
8
+ description = "AIGP governance adapter for llamaindex"
9
+ requires-python = ">=3.11"
10
+ dependencies = ["maigp-agent-core>=1.0.0"]
11
+
12
+ [tool.hatch.build.targets.wheel]
13
+ packages = ["aigp_llamaindex"]