swarmauri_workflow_documentassistant 0.1.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.
- swarmauri_workflow_documentassistant-0.1.0/LICENSE +201 -0
- swarmauri_workflow_documentassistant-0.1.0/NOTICE +4 -0
- swarmauri_workflow_documentassistant-0.1.0/PKG-INFO +101 -0
- swarmauri_workflow_documentassistant-0.1.0/README.md +66 -0
- swarmauri_workflow_documentassistant-0.1.0/pyproject.toml +55 -0
- swarmauri_workflow_documentassistant-0.1.0/swarmauri_workflow_documentassistant/DocumentAssistantWorkflow.py +206 -0
- swarmauri_workflow_documentassistant-0.1.0/swarmauri_workflow_documentassistant/__init__.py +7 -0
- swarmauri_workflow_documentassistant-0.1.0/swarmauri_workflow_documentassistant/app.py +11 -0
- swarmauri_workflow_documentassistant-0.1.0/swarmauri_workflow_documentassistant/cli.py +43 -0
- swarmauri_workflow_documentassistant-0.1.0/swarmauri_workflow_documentassistant/composition.py +178 -0
- swarmauri_workflow_documentassistant-0.1.0/swarmauri_workflow_documentassistant/demo.py +57 -0
- swarmauri_workflow_documentassistant-0.1.0/swarmauri_workflow_documentassistant/login.py +44 -0
- swarmauri_workflow_documentassistant-0.1.0/swarmauri_workflow_documentassistant/tools.py +31 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [2025] [Jacob Stewart @ Swarmauri]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: swarmauri_workflow_documentassistant
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Compose an authenticated document assistant.
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
License-File: NOTICE
|
|
8
|
+
Keywords: swarmauri,workflows,composition,execution,authorization
|
|
9
|
+
Author: Jacob Stewart
|
|
10
|
+
Author-email: jacob@swarmauri.com
|
|
11
|
+
Requires-Python: >=3.10,<3.13
|
|
12
|
+
Classifier: Development Status :: 1 - Planning
|
|
13
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Requires-Dist: swarmauri_agent_runner (>=0.1.2,<0.2)
|
|
18
|
+
Requires-Dist: swarmauri_base (>=0.11.0.dev13,<0.12)
|
|
19
|
+
Requires-Dist: swarmauri_core (>=0.11.0.dev8,<0.12)
|
|
20
|
+
Requires-Dist: swarmauri_delegation_attenuating (>=0.1.0,<0.2)
|
|
21
|
+
Requires-Dist: swarmauri_execution_default (>=0.1.0,<0.2)
|
|
22
|
+
Requires-Dist: swarmauri_grantstore_sqlite (>=0.1.0,<0.2)
|
|
23
|
+
Requires-Dist: swarmauri_invoker_default (>=0.1.0,<0.2)
|
|
24
|
+
Requires-Dist: swarmauri_keyprovider_local (>=0.11.0.dev1,<0.12)
|
|
25
|
+
Requires-Dist: swarmauri_permission_explicit (>=0.1.0,<0.2)
|
|
26
|
+
Requires-Dist: swarmauri_runstore_sqlite (>=0.1.0,<0.2)
|
|
27
|
+
Requires-Dist: swarmauri_standard (>=0.11.0.dev13,<0.12)
|
|
28
|
+
Requires-Dist: swarmauri_taskmanager_default (>=0.1.0,<0.2)
|
|
29
|
+
Requires-Dist: swarmauri_taskstore_sqlite (>=0.1.0,<0.2)
|
|
30
|
+
Requires-Dist: swarmauri_tokens_jwt (>=0.11.0.dev3,<0.12)
|
|
31
|
+
Requires-Dist: swarmauri_transport_httpx (>=0.1.0.dev4,<0.2)
|
|
32
|
+
Project-URL: Repository, https://github.com/swarmauri/swarmauri-sdk
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
|
|
35
|
+

|
|
36
|
+
|
|
37
|
+
# swarmauri_workflow_documentassistant
|
|
38
|
+
|
|
39
|
+
[](https://pepy.tech/project/swarmauri_workflow_documentassistant)
|
|
40
|
+
[](https://github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_workflow_documentassistant)
|
|
41
|
+
[](https://pypi.org/project/swarmauri_workflow_documentassistant)
|
|
42
|
+
[](LICENSE)
|
|
43
|
+
[](https://pypi.org/project/swarmauri_workflow_documentassistant)
|
|
44
|
+
|
|
45
|
+
Runnable reference composition built from injectable Swarmauri factors.
|
|
46
|
+
|
|
47
|
+
## Features
|
|
48
|
+
|
|
49
|
+
- Export `DocumentAssistantWorkflow` with SDK interface/base-class inheritance and entry-point discovery.
|
|
50
|
+
- Keep user authority, workload identity, lifecycle and delivery dependencies explicit.
|
|
51
|
+
- Reuse existing service registries, transports, checkpoints and token providers.
|
|
52
|
+
- Support Python 3.10, 3.11 and 3.12.
|
|
53
|
+
|
|
54
|
+
## Installation
|
|
55
|
+
|
|
56
|
+
These packages introduce unreleased core/base APIs. Install the matching workspace revision together; do not combine with older published core/base releases. Release validation must publish compatible dependency versions first.
|
|
57
|
+
|
|
58
|
+
```sh
|
|
59
|
+
uv pip install ./pkgs/standards/swarmauri_workflow_documentassistant
|
|
60
|
+
pip install ./pkgs/standards/swarmauri_workflow_documentassistant
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Usage
|
|
64
|
+
|
|
65
|
+
The following is composition code. Injected dependency names are host configuration, not bundled mock providers. Async statements run inside an async function.
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
# Explicit offline mode: scripted model and host-admitted demo identity.
|
|
69
|
+
# Real local keys, JWT verification, SQLite records and authority checks.
|
|
70
|
+
# No live IdP or model provider is impersonated.
|
|
71
|
+
# Run the installed reference command:
|
|
72
|
+
# swarmauri-workflow-documentassistant
|
|
73
|
+
|
|
74
|
+
from swarmauri_workflow_documentassistant import DocumentAssistantWorkflow
|
|
75
|
+
|
|
76
|
+
workflow = DocumentAssistantWorkflow.create(
|
|
77
|
+
directory, tokens=token_service, kid=signing_key_id, issuer=issuer,
|
|
78
|
+
model_factory=model_factory, authorize=authorize_user_resource,
|
|
79
|
+
documents=document_repository, permission=document_permission,
|
|
80
|
+
)
|
|
81
|
+
# subject comes from a verified host session, e.g. OIDCAdmission.complete().
|
|
82
|
+
result = await workflow.run(authenticated_subject)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
See [the complete architecture and deployment guide](../../../docs/examples/composable-execution/README.md) for concrete local commands, live OIDC integration, HTTP hosting, lifecycle semantics and failure recovery.
|
|
86
|
+
|
|
87
|
+
## Verification
|
|
88
|
+
|
|
89
|
+
From `pkgs/`, with the workspace dependencies installed:
|
|
90
|
+
|
|
91
|
+
```sh
|
|
92
|
+
uv run --package swarmauri_workflow_documentassistant --directory standards/swarmauri_workflow_documentassistant pytest
|
|
93
|
+
uv run --package swarmauri_workflow_documentassistant --directory standards/swarmauri_workflow_documentassistant ruff check .
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Tests use real signing and stores where applicable; scripted models are explicitly identified fixtures. No live provider interoperability is claimed by offline tests.
|
|
97
|
+
|
|
98
|
+
## Contributing
|
|
99
|
+
|
|
100
|
+
Follow the repository [contribution guide](https://github.com/swarmauri/swarmauri-sdk/blob/master/AGENTS.md).
|
|
101
|
+
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
# swarmauri_workflow_documentassistant
|
|
4
|
+
|
|
5
|
+
[](https://pepy.tech/project/swarmauri_workflow_documentassistant)
|
|
6
|
+
[](https://github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/standards/swarmauri_workflow_documentassistant)
|
|
7
|
+
[](https://pypi.org/project/swarmauri_workflow_documentassistant)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+
[](https://pypi.org/project/swarmauri_workflow_documentassistant)
|
|
10
|
+
|
|
11
|
+
Runnable reference composition built from injectable Swarmauri factors.
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- Export `DocumentAssistantWorkflow` with SDK interface/base-class inheritance and entry-point discovery.
|
|
16
|
+
- Keep user authority, workload identity, lifecycle and delivery dependencies explicit.
|
|
17
|
+
- Reuse existing service registries, transports, checkpoints and token providers.
|
|
18
|
+
- Support Python 3.10, 3.11 and 3.12.
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
These packages introduce unreleased core/base APIs. Install the matching workspace revision together; do not combine with older published core/base releases. Release validation must publish compatible dependency versions first.
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
uv pip install ./pkgs/standards/swarmauri_workflow_documentassistant
|
|
26
|
+
pip install ./pkgs/standards/swarmauri_workflow_documentassistant
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
The following is composition code. Injected dependency names are host configuration, not bundled mock providers. Async statements run inside an async function.
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
# Explicit offline mode: scripted model and host-admitted demo identity.
|
|
35
|
+
# Real local keys, JWT verification, SQLite records and authority checks.
|
|
36
|
+
# No live IdP or model provider is impersonated.
|
|
37
|
+
# Run the installed reference command:
|
|
38
|
+
# swarmauri-workflow-documentassistant
|
|
39
|
+
|
|
40
|
+
from swarmauri_workflow_documentassistant import DocumentAssistantWorkflow
|
|
41
|
+
|
|
42
|
+
workflow = DocumentAssistantWorkflow.create(
|
|
43
|
+
directory, tokens=token_service, kid=signing_key_id, issuer=issuer,
|
|
44
|
+
model_factory=model_factory, authorize=authorize_user_resource,
|
|
45
|
+
documents=document_repository, permission=document_permission,
|
|
46
|
+
)
|
|
47
|
+
# subject comes from a verified host session, e.g. OIDCAdmission.complete().
|
|
48
|
+
result = await workflow.run(authenticated_subject)
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
See [the complete architecture and deployment guide](../../../docs/examples/composable-execution/README.md) for concrete local commands, live OIDC integration, HTTP hosting, lifecycle semantics and failure recovery.
|
|
52
|
+
|
|
53
|
+
## Verification
|
|
54
|
+
|
|
55
|
+
From `pkgs/`, with the workspace dependencies installed:
|
|
56
|
+
|
|
57
|
+
```sh
|
|
58
|
+
uv run --package swarmauri_workflow_documentassistant --directory standards/swarmauri_workflow_documentassistant pytest
|
|
59
|
+
uv run --package swarmauri_workflow_documentassistant --directory standards/swarmauri_workflow_documentassistant ruff check .
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Tests use real signing and stores where applicable; scripted models are explicitly identified fixtures. No live provider interoperability is claimed by offline tests.
|
|
63
|
+
|
|
64
|
+
## Contributing
|
|
65
|
+
|
|
66
|
+
Follow the repository [contribution guide](https://github.com/swarmauri/swarmauri-sdk/blob/master/AGENTS.md).
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "swarmauri_workflow_documentassistant"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Compose an authenticated document assistant."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "Apache-2.0"
|
|
7
|
+
requires-python = ">=3.10,<3.13"
|
|
8
|
+
authors = [{ name = "Jacob Stewart", email = "jacob@swarmauri.com" }]
|
|
9
|
+
keywords = ["swarmauri", "workflows", "composition", "execution", "authorization"]
|
|
10
|
+
classifiers = [
|
|
11
|
+
"Development Status :: 1 - Planning",
|
|
12
|
+
"License :: OSI Approved :: Apache Software License",
|
|
13
|
+
"Programming Language :: Python :: 3.10",
|
|
14
|
+
"Programming Language :: Python :: 3.11",
|
|
15
|
+
"Programming Language :: Python :: 3.12",
|
|
16
|
+
]
|
|
17
|
+
dependencies = ["swarmauri_core>=0.11.0.dev8,<0.12", "swarmauri_base>=0.11.0.dev13,<0.12", "swarmauri_standard>=0.11.0.dev13,<0.12", "swarmauri_execution_default>=0.1.0,<0.2", "swarmauri_taskmanager_default>=0.1.0,<0.2", "swarmauri_taskstore_sqlite>=0.1.0,<0.2", "swarmauri_permission_explicit>=0.1.0,<0.2", "swarmauri_delegation_attenuating>=0.1.0,<0.2", "swarmauri_grantstore_sqlite>=0.1.0,<0.2", "swarmauri_invoker_default>=0.1.0,<0.2", "swarmauri_agent_runner>=0.1.2,<0.2", "swarmauri_runstore_sqlite>=0.1.0,<0.2", "swarmauri_tokens_jwt>=0.11.0.dev3,<0.12", "swarmauri_keyprovider_local>=0.11.0.dev1,<0.12", "swarmauri_transport_httpx>=0.1.0.dev4,<0.2"]
|
|
18
|
+
|
|
19
|
+
[project.urls]
|
|
20
|
+
Repository = "https://github.com/swarmauri/swarmauri-sdk"
|
|
21
|
+
|
|
22
|
+
[project.entry-points."swarmauri.workflows"]
|
|
23
|
+
DocumentAssistantWorkflow = "swarmauri_workflow_documentassistant:DocumentAssistantWorkflow"
|
|
24
|
+
|
|
25
|
+
[project.scripts]
|
|
26
|
+
swarmauri-workflow-documentassistant = "swarmauri_workflow_documentassistant.cli:main"
|
|
27
|
+
|
|
28
|
+
[tool.uv.sources]
|
|
29
|
+
swarmauri_core = { workspace = true }
|
|
30
|
+
swarmauri_base = { workspace = true }
|
|
31
|
+
swarmauri_standard = { workspace = true }
|
|
32
|
+
swarmauri_execution_default = { workspace = true }
|
|
33
|
+
swarmauri_taskmanager_default = { workspace = true }
|
|
34
|
+
swarmauri_taskstore_sqlite = { workspace = true }
|
|
35
|
+
swarmauri_permission_explicit = { workspace = true }
|
|
36
|
+
swarmauri_delegation_attenuating = { workspace = true }
|
|
37
|
+
swarmauri_grantstore_sqlite = { workspace = true }
|
|
38
|
+
swarmauri_invoker_default = { workspace = true }
|
|
39
|
+
swarmauri_agent_runner = { workspace = true }
|
|
40
|
+
swarmauri_runstore_sqlite = { workspace = true }
|
|
41
|
+
swarmauri_tokens_jwt = { workspace = true }
|
|
42
|
+
swarmauri_keyprovider_local = { workspace = true }
|
|
43
|
+
swarmauri_transport_httpx = { workspace = true }
|
|
44
|
+
|
|
45
|
+
[dependency-groups]
|
|
46
|
+
dev = ["pytest>=8", "pytest-asyncio", "ruff==0.15.21"]
|
|
47
|
+
|
|
48
|
+
[tool.pytest.ini_options]
|
|
49
|
+
asyncio_mode = "auto"
|
|
50
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
51
|
+
markers = ["unit: Unit tests", "i9n: Integration tests"]
|
|
52
|
+
|
|
53
|
+
[build-system]
|
|
54
|
+
requires = ["poetry-core>=1.0.0"]
|
|
55
|
+
build-backend = "poetry.core.masonry.api"
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"""Deliver authenticated task admission and a real tool-agent execution."""
|
|
2
|
+
|
|
3
|
+
import asyncio
|
|
4
|
+
import time
|
|
5
|
+
from typing import Any, Callable, Literal
|
|
6
|
+
from uuid import uuid4
|
|
7
|
+
|
|
8
|
+
from pydantic import Field
|
|
9
|
+
from swarmauri_base.ComponentBase import ComponentBase
|
|
10
|
+
from swarmauri_base.workflows import WorkflowDefinitionBase
|
|
11
|
+
from swarmauri_core.invocations import (
|
|
12
|
+
EdgeAuthorizationBinding,
|
|
13
|
+
InvocationContext,
|
|
14
|
+
InvocationRequest,
|
|
15
|
+
)
|
|
16
|
+
from swarmauri_core.permissions import Permission
|
|
17
|
+
from swarmauri_core.workflows import (
|
|
18
|
+
GraphDefinition,
|
|
19
|
+
NodeDefinition,
|
|
20
|
+
EdgeDefinition,
|
|
21
|
+
)
|
|
22
|
+
from swarmauri_agent_runner import AgentRunner, AgentRunnerExecutionDriver
|
|
23
|
+
|
|
24
|
+
from .composition import create_runtime
|
|
25
|
+
from .tools import AuthorizedDocumentTool
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@ComponentBase.register_type(
|
|
29
|
+
WorkflowDefinitionBase, "DocumentAssistantWorkflow"
|
|
30
|
+
)
|
|
31
|
+
class DocumentAssistantWorkflow(WorkflowDefinitionBase):
|
|
32
|
+
"""Compose injected identity, model, authorization and execution factors.
|
|
33
|
+
|
|
34
|
+
authorize(subject, permission) is the host's resource authorization hook.
|
|
35
|
+
A verified IdP identity alone does not grant access to a document.
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
type: Literal["DocumentAssistantWorkflow"] = "DocumentAssistantWorkflow"
|
|
39
|
+
runtime: Any = Field(exclude=True, repr=False)
|
|
40
|
+
model_factory: Callable = Field(exclude=True, repr=False)
|
|
41
|
+
authorize: Callable = Field(exclude=True, repr=False)
|
|
42
|
+
documents: dict[str, str] = Field(exclude=True, repr=False)
|
|
43
|
+
permission: Permission
|
|
44
|
+
runners: dict[str, Any] = Field(default_factory=dict, exclude=True)
|
|
45
|
+
execution_ids: dict[str, str] = Field(default_factory=dict, exclude=True)
|
|
46
|
+
|
|
47
|
+
@classmethod
|
|
48
|
+
def create(
|
|
49
|
+
cls,
|
|
50
|
+
directory,
|
|
51
|
+
*,
|
|
52
|
+
tokens,
|
|
53
|
+
kid,
|
|
54
|
+
issuer,
|
|
55
|
+
model_factory,
|
|
56
|
+
authorize,
|
|
57
|
+
documents,
|
|
58
|
+
permission,
|
|
59
|
+
http_client=None,
|
|
60
|
+
runtime_factory=create_runtime,
|
|
61
|
+
runtime_options=None,
|
|
62
|
+
):
|
|
63
|
+
edge = EdgeAuthorizationBinding(
|
|
64
|
+
"assistant-to-documents",
|
|
65
|
+
"agent:assistant",
|
|
66
|
+
"documents",
|
|
67
|
+
"read",
|
|
68
|
+
(permission,),
|
|
69
|
+
)
|
|
70
|
+
runtime = runtime_factory(
|
|
71
|
+
directory,
|
|
72
|
+
tokens=tokens,
|
|
73
|
+
kid=kid,
|
|
74
|
+
issuer=issuer,
|
|
75
|
+
edges={edge.edge_id: edge},
|
|
76
|
+
recipients={"documents": "service:documents"},
|
|
77
|
+
http_client=http_client,
|
|
78
|
+
**(runtime_options or {}),
|
|
79
|
+
)
|
|
80
|
+
workflow = cls(
|
|
81
|
+
runtime=runtime,
|
|
82
|
+
model_factory=model_factory,
|
|
83
|
+
authorize=authorize,
|
|
84
|
+
documents=documents,
|
|
85
|
+
permission=permission,
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
async def read(request, context):
|
|
89
|
+
return workflow.documents[request.permission.resource]
|
|
90
|
+
|
|
91
|
+
runtime.endpoint("documents", "service:documents", read)
|
|
92
|
+
return workflow
|
|
93
|
+
|
|
94
|
+
def definition(self):
|
|
95
|
+
return GraphDefinition(
|
|
96
|
+
"document-assistant",
|
|
97
|
+
"1",
|
|
98
|
+
(
|
|
99
|
+
NodeDefinition("assistant", "assistant"),
|
|
100
|
+
NodeDefinition("documents", "documents"),
|
|
101
|
+
),
|
|
102
|
+
(
|
|
103
|
+
EdgeDefinition(
|
|
104
|
+
"assistant-to-documents", "assistant", "documents"
|
|
105
|
+
),
|
|
106
|
+
),
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
def bind_runner(self, task_id, grant_id, resource, actor, edge_id):
|
|
110
|
+
"""Reconstruct a driver after restart using durable run checkpoints."""
|
|
111
|
+
context = InvocationContext(actor, task_id, grant_id)
|
|
112
|
+
loop = asyncio.get_running_loop()
|
|
113
|
+
|
|
114
|
+
def invoke(requested_resource):
|
|
115
|
+
permission = Permission(
|
|
116
|
+
"documents:read", requested_resource, self.permission.tenant
|
|
117
|
+
)
|
|
118
|
+
request = InvocationRequest(
|
|
119
|
+
str(uuid4()),
|
|
120
|
+
edge_id,
|
|
121
|
+
task_id,
|
|
122
|
+
"read",
|
|
123
|
+
permission,
|
|
124
|
+
{"resource": requested_resource},
|
|
125
|
+
)
|
|
126
|
+
future = asyncio.run_coroutine_threadsafe(
|
|
127
|
+
self.runtime.invoker.invoke(
|
|
128
|
+
request,
|
|
129
|
+
InvocationContext(
|
|
130
|
+
context.actor,
|
|
131
|
+
context.task_id,
|
|
132
|
+
context.grant_id,
|
|
133
|
+
self.execution_ids.get(driver_id),
|
|
134
|
+
),
|
|
135
|
+
),
|
|
136
|
+
loop,
|
|
137
|
+
)
|
|
138
|
+
return future.result(timeout=30).value
|
|
139
|
+
|
|
140
|
+
runner = AgentRunner(
|
|
141
|
+
self.model_factory(resource),
|
|
142
|
+
self.runtime.checkpoints,
|
|
143
|
+
tools={"ReadDocument": AuthorizedDocumentTool(callback=invoke)},
|
|
144
|
+
)
|
|
145
|
+
driver_id = f"assistant:{task_id}:{actor}"
|
|
146
|
+
self.runtime.controller.drivers[driver_id] = (
|
|
147
|
+
AgentRunnerExecutionDriver(
|
|
148
|
+
runner=runner,
|
|
149
|
+
before_step=lambda snapshot: self.execution_ids.__setitem__(
|
|
150
|
+
driver_id, snapshot.execution_id
|
|
151
|
+
),
|
|
152
|
+
)
|
|
153
|
+
)
|
|
154
|
+
self.runners[driver_id] = runner
|
|
155
|
+
return driver_id
|
|
156
|
+
|
|
157
|
+
def start(self, subject, *, lifetime=600):
|
|
158
|
+
"""Admit a host-authenticated subject after resource authorization."""
|
|
159
|
+
if lifetime <= 0 or not self.authorize(subject, self.permission):
|
|
160
|
+
raise PermissionError("User cannot start this document task")
|
|
161
|
+
task = self.runtime.manager.start(
|
|
162
|
+
subject,
|
|
163
|
+
self.permission.tenant,
|
|
164
|
+
(self.permission,),
|
|
165
|
+
int(time.time()) + lifetime,
|
|
166
|
+
)
|
|
167
|
+
root = self.runtime.delegations.root(
|
|
168
|
+
task.task_id, "agent:assistant", (self.permission,), 1
|
|
169
|
+
)
|
|
170
|
+
driver = self.bind_runner(
|
|
171
|
+
task.task_id,
|
|
172
|
+
root.grant_id,
|
|
173
|
+
self.permission.resource,
|
|
174
|
+
"agent:assistant",
|
|
175
|
+
"assistant-to-documents",
|
|
176
|
+
)
|
|
177
|
+
return self.runtime.controller.start(
|
|
178
|
+
task.task_id,
|
|
179
|
+
driver,
|
|
180
|
+
{
|
|
181
|
+
"prompt": self.permission.resource,
|
|
182
|
+
"grant_id": root.grant_id,
|
|
183
|
+
"resource": self.permission.resource,
|
|
184
|
+
},
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
def restore(self, execution_id):
|
|
188
|
+
snapshot = self.runtime.controller.get(execution_id)
|
|
189
|
+
self.bind_runner(
|
|
190
|
+
snapshot.task_id,
|
|
191
|
+
snapshot.state["grant_id"],
|
|
192
|
+
snapshot.state["resource"],
|
|
193
|
+
"agent:assistant",
|
|
194
|
+
"assistant-to-documents",
|
|
195
|
+
)
|
|
196
|
+
return snapshot
|
|
197
|
+
|
|
198
|
+
async def run(self, subject):
|
|
199
|
+
snapshot = self.start(subject)
|
|
200
|
+
for _ in range(100):
|
|
201
|
+
snapshot = await self.runtime.controller.advance(
|
|
202
|
+
snapshot.execution_id
|
|
203
|
+
)
|
|
204
|
+
if snapshot.status not in {"ready", "running"}:
|
|
205
|
+
return snapshot
|
|
206
|
+
raise RuntimeError("Reference execution step limit reached")
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""Expose the composition's receiving app through existing transports."""
|
|
2
|
+
|
|
3
|
+
from .login import OIDCAdmission
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def document_app(workflow):
|
|
7
|
+
"""Return HttpApp; use .asgi with an existing ASGI server transport."""
|
|
8
|
+
return workflow.runtime.endpoints["documents"]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
__all__ = ["document_app", "OIDCAdmission"]
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"""Run the explicitly offline reference composition."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import asyncio
|
|
5
|
+
import tempfile
|
|
6
|
+
from dataclasses import asdict
|
|
7
|
+
import json
|
|
8
|
+
|
|
9
|
+
from swarmauri_core.permissions import Permission
|
|
10
|
+
from .DocumentAssistantWorkflow import DocumentAssistantWorkflow
|
|
11
|
+
from .demo import ScriptedDocumentModel, demo_tokens
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
async def run(directory):
|
|
15
|
+
tokens, kid, issuer = await demo_tokens()
|
|
16
|
+
workflow = DocumentAssistantWorkflow.create(
|
|
17
|
+
directory,
|
|
18
|
+
tokens=tokens,
|
|
19
|
+
kid=kid,
|
|
20
|
+
issuer=issuer,
|
|
21
|
+
model_factory=ScriptedDocumentModel,
|
|
22
|
+
authorize=lambda subject, permission: subject == "demo:alice",
|
|
23
|
+
documents={"document:123": "Revenue increased by 12%."},
|
|
24
|
+
permission=Permission("documents:read", "document:123", "demo"),
|
|
25
|
+
)
|
|
26
|
+
result = await workflow.run("demo:alice")
|
|
27
|
+
return result, workflow.runtime.events
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def main():
|
|
31
|
+
parser = argparse.ArgumentParser(
|
|
32
|
+
description="Offline fixture model with real JWT/grant verification"
|
|
33
|
+
)
|
|
34
|
+
parser.parse_args()
|
|
35
|
+
with tempfile.TemporaryDirectory() as directory:
|
|
36
|
+
result, trace = asyncio.run(run(directory))
|
|
37
|
+
print(json.dumps({"execution": asdict(result), "trace": trace}, indent=2))
|
|
38
|
+
if result.status != "completed":
|
|
39
|
+
raise SystemExit(1)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
if __name__ == "__main__":
|
|
43
|
+
main()
|
swarmauri_workflow_documentassistant-0.1.0/swarmauri_workflow_documentassistant/composition.py
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"""Wire existing factors into an injectable reference runtime."""
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from swarmauri_standard.service_registries.ServiceRegistry import (
|
|
7
|
+
ServiceRegistry,
|
|
8
|
+
)
|
|
9
|
+
from swarmauri_runstore_sqlite import SqliteRunStore
|
|
10
|
+
from swarmauri_execution_default import DefaultExecutionController
|
|
11
|
+
from swarmauri_taskmanager_default import DefaultTaskManager
|
|
12
|
+
from swarmauri_taskstore_sqlite import SqliteTaskStore
|
|
13
|
+
from swarmauri_grantstore_sqlite import SqliteGrantStore
|
|
14
|
+
from swarmauri_permission_explicit import ExplicitPermissionPolicy
|
|
15
|
+
from swarmauri_delegation_attenuating import AttenuatingDelegationService
|
|
16
|
+
from swarmauri_invoker_default import (
|
|
17
|
+
DefaultInvoker,
|
|
18
|
+
DelegatedAuthorityStrategy,
|
|
19
|
+
InvocationEndpoint,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@dataclass
|
|
24
|
+
class ReferenceRuntime:
|
|
25
|
+
"""Keep infrastructure dependencies explicit and replaceable."""
|
|
26
|
+
|
|
27
|
+
tasks: object
|
|
28
|
+
grants: object
|
|
29
|
+
checkpoints: object
|
|
30
|
+
policy: object
|
|
31
|
+
delegations: object
|
|
32
|
+
controller: object
|
|
33
|
+
manager: object
|
|
34
|
+
services: object
|
|
35
|
+
invoker: object
|
|
36
|
+
tokens: object
|
|
37
|
+
issuer: str
|
|
38
|
+
endpoints: dict
|
|
39
|
+
edges: dict
|
|
40
|
+
events: list[dict] = field(default_factory=list)
|
|
41
|
+
|
|
42
|
+
def endpoint(self, name, subject, handler):
|
|
43
|
+
"""Install the same receiving application used by HTTP delivery."""
|
|
44
|
+
|
|
45
|
+
async def admitted(request, context):
|
|
46
|
+
grant = (
|
|
47
|
+
self.grants.load(context.grant_id)
|
|
48
|
+
if context.grant_id
|
|
49
|
+
else None
|
|
50
|
+
)
|
|
51
|
+
self.events.append(
|
|
52
|
+
{
|
|
53
|
+
"invocation_id": request.invocation_id,
|
|
54
|
+
"task_id": context.task_id,
|
|
55
|
+
"recipient": context.actor,
|
|
56
|
+
"resource": request.permission.resource,
|
|
57
|
+
"remaining_depth": (
|
|
58
|
+
grant.remaining_depth if grant is not None else None
|
|
59
|
+
),
|
|
60
|
+
}
|
|
61
|
+
)
|
|
62
|
+
return await handler(request, context)
|
|
63
|
+
|
|
64
|
+
endpoint = InvocationEndpoint(
|
|
65
|
+
service=subject,
|
|
66
|
+
audience=subject,
|
|
67
|
+
edges={k: v for k, v in self.edges.items() if v.service == name},
|
|
68
|
+
tokens=self.tokens,
|
|
69
|
+
issuer=self.issuer,
|
|
70
|
+
tasks=self.tasks,
|
|
71
|
+
policy=self.policy,
|
|
72
|
+
checkpoints=self.checkpoints,
|
|
73
|
+
handler=admitted,
|
|
74
|
+
delegations=self.delegations,
|
|
75
|
+
)
|
|
76
|
+
self.endpoints[name] = endpoint
|
|
77
|
+
self.services.register_service(
|
|
78
|
+
name,
|
|
79
|
+
{
|
|
80
|
+
"subject": subject,
|
|
81
|
+
"audience": subject,
|
|
82
|
+
"endpoint": name,
|
|
83
|
+
"protocol": "local",
|
|
84
|
+
},
|
|
85
|
+
)
|
|
86
|
+
return endpoint
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def create_runtime(
|
|
90
|
+
directory,
|
|
91
|
+
*,
|
|
92
|
+
tokens,
|
|
93
|
+
kid,
|
|
94
|
+
issuer,
|
|
95
|
+
edges,
|
|
96
|
+
recipients,
|
|
97
|
+
http_client=None,
|
|
98
|
+
algorithm="RS256",
|
|
99
|
+
tasks=None,
|
|
100
|
+
grants=None,
|
|
101
|
+
checkpoints=None,
|
|
102
|
+
policy=None,
|
|
103
|
+
services=None,
|
|
104
|
+
delegations=None,
|
|
105
|
+
):
|
|
106
|
+
"""Use SQLite, service discovery, token services and existing HTTP I/O."""
|
|
107
|
+
directory = Path(directory)
|
|
108
|
+
directory.mkdir(parents=True, exist_ok=True)
|
|
109
|
+
tasks = (
|
|
110
|
+
tasks
|
|
111
|
+
if tasks is not None
|
|
112
|
+
else SqliteTaskStore(path=directory / "tasks.db")
|
|
113
|
+
)
|
|
114
|
+
grants = (
|
|
115
|
+
grants
|
|
116
|
+
if grants is not None
|
|
117
|
+
else SqliteGrantStore(path=directory / "grants.db")
|
|
118
|
+
)
|
|
119
|
+
checkpoints = (
|
|
120
|
+
checkpoints
|
|
121
|
+
if checkpoints is not None
|
|
122
|
+
else SqliteRunStore(path=directory / "runs.db")
|
|
123
|
+
)
|
|
124
|
+
policy = policy if policy is not None else ExplicitPermissionPolicy()
|
|
125
|
+
delegations = (
|
|
126
|
+
delegations
|
|
127
|
+
if delegations is not None
|
|
128
|
+
else AttenuatingDelegationService(
|
|
129
|
+
grants=grants,
|
|
130
|
+
tasks=tasks,
|
|
131
|
+
policy=policy,
|
|
132
|
+
tokens=tokens,
|
|
133
|
+
kid=kid,
|
|
134
|
+
issuer=issuer,
|
|
135
|
+
algorithm=algorithm,
|
|
136
|
+
edges=frozenset(
|
|
137
|
+
(edge.caller, recipients[edge.service])
|
|
138
|
+
for edge in edges.values()
|
|
139
|
+
),
|
|
140
|
+
)
|
|
141
|
+
)
|
|
142
|
+
controller = DefaultExecutionController(
|
|
143
|
+
checkpoints=checkpoints, tasks=tasks, drivers={}
|
|
144
|
+
)
|
|
145
|
+
manager = DefaultTaskManager(store=tasks, executions=controller)
|
|
146
|
+
services = services if services is not None else ServiceRegistry()
|
|
147
|
+
endpoints = {}
|
|
148
|
+
authorities = {
|
|
149
|
+
key: DelegatedAuthorityStrategy(
|
|
150
|
+
delegations=delegations, recipient=recipients[edge.service]
|
|
151
|
+
)
|
|
152
|
+
for key, edge in edges.items()
|
|
153
|
+
}
|
|
154
|
+
invoker = DefaultInvoker(
|
|
155
|
+
services=services,
|
|
156
|
+
policy=policy,
|
|
157
|
+
edges=edges,
|
|
158
|
+
authorities=authorities,
|
|
159
|
+
http_client=http_client,
|
|
160
|
+
local_endpoints=endpoints,
|
|
161
|
+
)
|
|
162
|
+
# Pydantic copies mappings during validation. Expose the actual mapping.
|
|
163
|
+
endpoints = invoker.local_endpoints
|
|
164
|
+
return ReferenceRuntime(
|
|
165
|
+
tasks,
|
|
166
|
+
grants,
|
|
167
|
+
checkpoints,
|
|
168
|
+
policy,
|
|
169
|
+
delegations,
|
|
170
|
+
controller,
|
|
171
|
+
manager,
|
|
172
|
+
services,
|
|
173
|
+
invoker,
|
|
174
|
+
tokens,
|
|
175
|
+
issuer,
|
|
176
|
+
endpoints,
|
|
177
|
+
edges,
|
|
178
|
+
)
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""Explicit offline fixtures; real signing, stores and authorization."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from swarmauri_keyprovider_local import LocalKeyProvider
|
|
5
|
+
from swarmauri_core.key_providers.types import (
|
|
6
|
+
KeySpec,
|
|
7
|
+
KeyAlg,
|
|
8
|
+
KeyClass,
|
|
9
|
+
KeyUse,
|
|
10
|
+
ExportPolicy,
|
|
11
|
+
)
|
|
12
|
+
from swarmauri_tokens_jwt import JWTTokenService
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class ScriptedDocumentModel:
|
|
16
|
+
"""Deterministic model fixture, not an identity or token provider."""
|
|
17
|
+
|
|
18
|
+
def __init__(self, resource):
|
|
19
|
+
self.resource = resource
|
|
20
|
+
|
|
21
|
+
def __call__(self, messages, tools):
|
|
22
|
+
results = [m for m in messages if m.get("role") == "tool"]
|
|
23
|
+
if results:
|
|
24
|
+
return {
|
|
25
|
+
"role": "assistant",
|
|
26
|
+
"content": "Document result: " + results[-1]["content"],
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
"role": "assistant",
|
|
30
|
+
"content": None,
|
|
31
|
+
"tool_calls": [
|
|
32
|
+
{
|
|
33
|
+
"id": "read-document",
|
|
34
|
+
"type": "function",
|
|
35
|
+
"function": {
|
|
36
|
+
"name": "ReadDocument",
|
|
37
|
+
"arguments": json.dumps({"resource": self.resource}),
|
|
38
|
+
},
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
async def demo_tokens():
|
|
45
|
+
"""Generate ephemeral local keys; production hosts inject durable keys."""
|
|
46
|
+
keys = LocalKeyProvider()
|
|
47
|
+
ref = await keys.create_key(
|
|
48
|
+
KeySpec(
|
|
49
|
+
klass=KeyClass.asymmetric,
|
|
50
|
+
alg=KeyAlg.RSA_PSS_SHA256,
|
|
51
|
+
uses=(KeyUse.SIGN, KeyUse.VERIFY),
|
|
52
|
+
export_policy=ExportPolicy.SECRET_WHEN_ALLOWED,
|
|
53
|
+
size_bits=2048,
|
|
54
|
+
)
|
|
55
|
+
)
|
|
56
|
+
issuer = "https://reference.local"
|
|
57
|
+
return JWTTokenService(keys, default_issuer=issuer), ref.kid, issuer
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""Bind existing OAuth/OIDC adapters to a one-use browser login session."""
|
|
2
|
+
|
|
3
|
+
import secrets
|
|
4
|
+
import time
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from typing import Callable
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@dataclass
|
|
10
|
+
class OIDCAdmission:
|
|
11
|
+
"""Correlate provider state with a host-controlled browser session.
|
|
12
|
+
|
|
13
|
+
The web host stores browser_binding in a Secure, HttpOnly, SameSite cookie.
|
|
14
|
+
Identity resolution maps verified provider identity to a local subject.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
login: object
|
|
18
|
+
resolve_identity: Callable
|
|
19
|
+
pending: dict = field(default_factory=dict)
|
|
20
|
+
lifetime: int = 300
|
|
21
|
+
|
|
22
|
+
async def begin(self):
|
|
23
|
+
now = time.time()
|
|
24
|
+
self.pending = {
|
|
25
|
+
key: item for key, item in self.pending.items() if item[1] > now
|
|
26
|
+
}
|
|
27
|
+
if len(self.pending) >= 1000:
|
|
28
|
+
raise RuntimeError("Too many pending logins")
|
|
29
|
+
payload = await self.login.auth_url()
|
|
30
|
+
browser_binding = secrets.token_urlsafe(32)
|
|
31
|
+
self.pending[payload["state"]] = (browser_binding, now + self.lifetime)
|
|
32
|
+
return payload, browser_binding
|
|
33
|
+
|
|
34
|
+
async def complete(self, code, state, browser_binding):
|
|
35
|
+
expected, expiry = self.pending.get(state, ("", 0))
|
|
36
|
+
if (
|
|
37
|
+
expiry <= time.time()
|
|
38
|
+
or not browser_binding
|
|
39
|
+
or not secrets.compare_digest(expected, browser_binding)
|
|
40
|
+
):
|
|
41
|
+
raise PermissionError("Login session mismatch or expiry")
|
|
42
|
+
self.pending.pop(state)
|
|
43
|
+
identity = await self.login.exchange_and_identity(code, state)
|
|
44
|
+
return self.resolve_identity(identity)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""Model-visible arguments exclude task authority and credentials."""
|
|
2
|
+
|
|
3
|
+
from collections.abc import Callable
|
|
4
|
+
from typing import Literal
|
|
5
|
+
from pydantic import Field
|
|
6
|
+
from swarmauri_base.ComponentBase import ComponentBase
|
|
7
|
+
from swarmauri_base.tools.ToolBase import ToolBase
|
|
8
|
+
from swarmauri_base.tools.ParameterBase import ParameterBase
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@ComponentBase.register_type(ToolBase, "AuthorizedDocumentTool")
|
|
12
|
+
class AuthorizedDocumentTool(ToolBase):
|
|
13
|
+
"""Read one resource through a host-bound invocation function."""
|
|
14
|
+
|
|
15
|
+
type: Literal["AuthorizedDocumentTool"] = "AuthorizedDocumentTool"
|
|
16
|
+
name: str = "ReadDocument"
|
|
17
|
+
description: str = "Read a document permitted for the current task."
|
|
18
|
+
callback: Callable = Field(exclude=True, repr=False)
|
|
19
|
+
parameters: list[ParameterBase] = Field(
|
|
20
|
+
default_factory=lambda: [
|
|
21
|
+
ParameterBase(
|
|
22
|
+
name="resource",
|
|
23
|
+
input_type="string",
|
|
24
|
+
description="Exact document resource identifier",
|
|
25
|
+
required=True,
|
|
26
|
+
)
|
|
27
|
+
]
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
def __call__(self, resource: str):
|
|
31
|
+
return self.callback(resource)
|