cred-semantic-kernel 1.0.0__py3-none-any.whl

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,5 @@
1
+ """Cred Semantic Kernel integration."""
2
+
3
+ from .plugin import CredPlugin
4
+
5
+ __all__ = ["CredPlugin"]
@@ -0,0 +1,88 @@
1
+ """Cred Semantic Kernel Plugin.
2
+
3
+ Provides a kernel function that delegates OAuth credentials for AI agents.
4
+ The plugin is pre-configured with agent identity and app context at construction.
5
+ At runtime, the agent provides ``service`` and ``scopes`` as function parameters.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import json
11
+ from typing import Annotated, Optional
12
+
13
+ from semantic_kernel.functions import kernel_function
14
+
15
+ from cred import Cred
16
+
17
+
18
+ class CredPlugin:
19
+ """Semantic Kernel plugin for Cred credential delegation.
20
+
21
+ Pre-configured at construction with the agent token, user ID, and
22
+ app client ID. Exposes a single ``delegate`` kernel function.
23
+
24
+ Example::
25
+
26
+ from cred_semantic_kernel import CredPlugin
27
+ import semantic_kernel as sk
28
+
29
+ kernel = sk.Kernel()
30
+ plugin = CredPlugin(
31
+ agent_token=os.environ["CRED_AGENT_TOKEN"],
32
+ user_id="user_123",
33
+ app_client_id="my_app",
34
+ )
35
+ kernel.add_plugin(plugin, plugin_name="cred")
36
+
37
+ Raises:
38
+ ConsentRequiredError: (from delegate at runtime) when the user hasn't
39
+ connected the requested service. The error message includes
40
+ ``consent_url`` so the caller can redirect the user.
41
+ """
42
+
43
+ def __init__(
44
+ self,
45
+ agent_token: str,
46
+ user_id: str,
47
+ app_client_id: str,
48
+ base_url: str = "https://api.cred.ninja",
49
+ ) -> None:
50
+ self._cred = Cred(agent_token=agent_token, base_url=base_url)
51
+ self._user_id = user_id
52
+ self._app_client_id = app_client_id
53
+
54
+ @kernel_function(
55
+ name="delegate",
56
+ description=(
57
+ "Get a delegated OAuth access token for a third-party service "
58
+ "on behalf of the current user. "
59
+ "Returns JSON with access_token, token_type, expires_in, service, scopes, "
60
+ "and delegation_id. "
61
+ "Raises an error with consent_url if the user hasn't connected the service."
62
+ ),
63
+ )
64
+ def delegate(
65
+ self,
66
+ service: Annotated[str, "Service slug to get a token for (e.g. 'google', 'github', 'google-calendar')."],
67
+ scopes: Annotated[str, "Comma-separated OAuth scopes to request (e.g. 'calendar.readonly,calendar.events'). Pass empty string to use all consented scopes."],
68
+ ) -> str:
69
+ """Delegate credentials and return JSON result."""
70
+ scope_list: Optional[list[str]] = None
71
+ if scopes:
72
+ scope_list = [s.strip() for s in scopes.split(",") if s.strip()]
73
+
74
+ result = self._cred.delegate(
75
+ service=service,
76
+ user_id=self._user_id,
77
+ app_client_id=self._app_client_id,
78
+ scopes=scope_list if scope_list else None,
79
+ )
80
+
81
+ return json.dumps({
82
+ "access_token": result.access_token,
83
+ "token_type": result.token_type,
84
+ "expires_in": result.expires_in,
85
+ "service": result.service,
86
+ "scopes": result.scopes,
87
+ "delegation_id": result.delegation_id,
88
+ })
@@ -0,0 +1,76 @@
1
+ Metadata-Version: 2.4
2
+ Name: cred-semantic-kernel
3
+ Version: 1.0.0
4
+ Summary: Cred Semantic Kernel integration — credential delegation plugin for Microsoft Semantic Kernel agents
5
+ Author-email: Cred <hello@cred.ninja>
6
+ License: Apache-2.0
7
+ Keywords: ai-agents,cred,delegation,microsoft,oauth,semantic-kernel
8
+ Requires-Python: >=3.9
9
+ Requires-Dist: cred-auth>=0.1.0
10
+ Requires-Dist: semantic-kernel>=1.0
11
+ Provides-Extra: dev
12
+ Requires-Dist: hatchling; extra == 'dev'
13
+ Requires-Dist: pytest-asyncio>=0.21; extra == 'dev'
14
+ Requires-Dist: pytest>=7.0; extra == 'dev'
15
+ Description-Content-Type: text/markdown
16
+
17
+ # cred-semantic-kernel
18
+
19
+ Microsoft Semantic Kernel integration for Cred. OAuth2 credential delegation for AI agents.
20
+
21
+ ## Install
22
+
23
+ ```bash
24
+ pip install cred-semantic-kernel
25
+ ```
26
+
27
+ ## Quick Start
28
+
29
+ ```python
30
+ import os
31
+ import semantic_kernel as sk
32
+ from cred_semantic_kernel import CredPlugin
33
+
34
+ kernel = sk.Kernel()
35
+
36
+ plugin = CredPlugin(
37
+ agent_token=os.environ["CRED_AGENT_TOKEN"],
38
+ user_id="user_123",
39
+ app_client_id="my_app_client_id",
40
+ )
41
+
42
+ kernel.add_plugin(plugin, plugin_name="cred")
43
+ ```
44
+
45
+ ## Plugin Functions
46
+
47
+ The `cred` plugin exposes one kernel function:
48
+
49
+ ### `delegate`
50
+
51
+ | Parameter | Type | Description |
52
+ |-----------|------|-------------|
53
+ | `service` | `string` | Service slug (e.g. `google`, `github`) |
54
+ | `scopes` | `string` | Comma-separated OAuth scopes to request |
55
+
56
+ `user_id` and `app_client_id` are pre-configured at construction time, not agent-controlled.
57
+
58
+ Returns a JSON string with `access_token`, `token_type`, `expires_in`, `service`, `scopes`, and `delegation_id`.
59
+
60
+ ## Handling Consent
61
+
62
+ When the user hasn't connected the service, the `delegate` function raises `ConsentRequiredError`.
63
+ The error's `consent_url` attribute contains the URL to redirect the user.
64
+
65
+ ```python
66
+ from cred import ConsentRequiredError
67
+
68
+ try:
69
+ result = plugin.delegate(service="google", scopes="calendar.readonly")
70
+ except ConsentRequiredError as e:
71
+ print(f"Redirect user to: {e.consent_url}")
72
+ ```
73
+
74
+ ## Cred Cloud (Coming Soon)
75
+
76
+ Managed cloud delegation is coming. [Join the waitlist](https://cred.ninja/waitlist).
@@ -0,0 +1,5 @@
1
+ cred_semantic_kernel/__init__.py,sha256=ejIyOJMMuOMUxxOs6izztuLre4Y4wLlVk1sjg0kiQaQ,98
2
+ cred_semantic_kernel/plugin.py,sha256=Hr7hd7DTCpuxlMgLNgJm-XuqZkoqxPNV-DlYbm3VnmQ,3038
3
+ cred_semantic_kernel-1.0.0.dist-info/METADATA,sha256=QVaF8E4FfQr-U3yUAkAOjIBQqbhPAyYbjHj8uRRlZgY,2105
4
+ cred_semantic_kernel-1.0.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
5
+ cred_semantic_kernel-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.29.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any