foundgine 3.4.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.
- foundgine-3.4.0/.gitignore +7 -0
- foundgine-3.4.0/LICENSE +181 -0
- foundgine-3.4.0/PKG-INFO +131 -0
- foundgine-3.4.0/README.md +109 -0
- foundgine-3.4.0/pyproject.toml +53 -0
- foundgine-3.4.0/src/foundgine/__init__.py +56 -0
- foundgine-3.4.0/src/foundgine/_http.py +50 -0
- foundgine-3.4.0/src/foundgine/client.py +145 -0
- foundgine-3.4.0/src/foundgine/errors.py +60 -0
- foundgine-3.4.0/src/foundgine/http.py +87 -0
- foundgine-3.4.0/src/foundgine/mcp.py +306 -0
- foundgine-3.4.0/src/foundgine/py.typed +0 -0
- foundgine-3.4.0/src/foundgine/sse.py +103 -0
- foundgine-3.4.0/src/foundgine/sync.py +172 -0
- foundgine-3.4.0/src/foundgine/types.py +48 -0
- foundgine-3.4.0/src/foundgine/workflows.py +428 -0
- foundgine-3.4.0/tests/conftest.py +34 -0
- foundgine-3.4.0/tests/helpers.py +56 -0
- foundgine-3.4.0/tests/test_client.py +369 -0
- foundgine-3.4.0/tests/test_conformance.py +153 -0
- foundgine-3.4.0/tests/test_errors.py +48 -0
- foundgine-3.4.0/tests/test_loopback.py +120 -0
- foundgine-3.4.0/tests/test_sse_parser.py +121 -0
- foundgine-3.4.0/tests/test_sync.py +76 -0
- foundgine-3.4.0/tests/test_workflows.py +336 -0
foundgine-3.4.0/LICENSE
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
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
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
|
67
|
+
permissions granted by this License.
|
|
68
|
+
|
|
69
|
+
2. Grant of Copyright License.
|
|
70
|
+
|
|
71
|
+
Subject to the terms and conditions of this License, each Contributor
|
|
72
|
+
hereby grants to You a perpetual, worldwide, non-exclusive, no-charge,
|
|
73
|
+
royalty-free, irrevocable copyright license to reproduce, prepare
|
|
74
|
+
Derivative Works of, publicly display, publicly perform, sublicense,
|
|
75
|
+
and distribute the Work and such Derivative Works in Source or Object
|
|
76
|
+
form.
|
|
77
|
+
|
|
78
|
+
3. Grant of Patent License.
|
|
79
|
+
|
|
80
|
+
Subject to the terms and conditions of this License, each Contributor
|
|
81
|
+
hereby grants to You a perpetual, worldwide, non-exclusive, no-charge,
|
|
82
|
+
royalty-free, irrevocable (except as stated in this section) patent
|
|
83
|
+
license to make, have made, use, offer to sell, sell, import, and
|
|
84
|
+
otherwise transfer the Work, where such license applies only to those
|
|
85
|
+
patent claims licensable by such Contributor that are necessarily
|
|
86
|
+
infringed by their Contribution(s) alone or by combination of their
|
|
87
|
+
Contribution(s) with the Work to which such Contribution(s) was
|
|
88
|
+
submitted. If You institute patent litigation against any entity
|
|
89
|
+
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
|
90
|
+
the Work or a Contribution incorporated within the Work constitutes
|
|
91
|
+
direct or contributory patent infringement, then any patent licenses
|
|
92
|
+
granted to You under this License for that Work shall terminate
|
|
93
|
+
as of the date such litigation is filed.
|
|
94
|
+
|
|
95
|
+
4. Redistribution. You may reproduce and distribute copies of the Work
|
|
96
|
+
or Derivative Works thereof in any medium, with or without
|
|
97
|
+
modifications, and in Source or Object form, provided that You meet
|
|
98
|
+
the following conditions:
|
|
99
|
+
|
|
100
|
+
(a) You must give any other recipients of the Work or Derivative Works
|
|
101
|
+
a copy of this License; and
|
|
102
|
+
|
|
103
|
+
(b) You must cause any modified files to carry prominent notices
|
|
104
|
+
stating that You changed the files; and
|
|
105
|
+
|
|
106
|
+
(c) You must retain, in the Source form of any Derivative Works that
|
|
107
|
+
You distribute, all copyright, patent, trademark, and attribution
|
|
108
|
+
notices from the Source form of the Work, excluding those notices
|
|
109
|
+
that do not pertain to any part of the Derivative Works; and
|
|
110
|
+
|
|
111
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
112
|
+
distribution, then any Derivative Works that You distribute must
|
|
113
|
+
include a readable copy of the attribution notices contained
|
|
114
|
+
within such NOTICE file, excluding those notices that do not
|
|
115
|
+
pertain to any part of the Derivative Works, in at least one of
|
|
116
|
+
the following places: within a NOTICE text file distributed as
|
|
117
|
+
part of the Derivative Works; within the Source form or
|
|
118
|
+
documentation, if provided along with the Derivative Works; or,
|
|
119
|
+
within a display generated by the Derivative Works, if and
|
|
120
|
+
wherever such third-party notices normally appear. The contents
|
|
121
|
+
of the NOTICE file are for informational purposes only and
|
|
122
|
+
do not modify the License. You may add Your own attribution
|
|
123
|
+
notices within Derivative Works that You distribute, alongside
|
|
124
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
125
|
+
that such additional attribution notices cannot be construed
|
|
126
|
+
as modifying the License.
|
|
127
|
+
|
|
128
|
+
You may add Your own copyright statement to Your modifications and
|
|
129
|
+
may provide additional or different license terms and conditions
|
|
130
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
131
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
132
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
133
|
+
the conditions stated in this License.
|
|
134
|
+
|
|
135
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
136
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
137
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
138
|
+
this License, without any additional terms or conditions.
|
|
139
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
140
|
+
the terms of any separate license agreement you may have executed
|
|
141
|
+
with Licensor regarding such Contributions.
|
|
142
|
+
|
|
143
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
144
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
145
|
+
except as required for reasonable and customary use in describing the
|
|
146
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
147
|
+
|
|
148
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
149
|
+
agreed to in writing, Licensor provides the Work (and each Contributor
|
|
150
|
+
provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES
|
|
151
|
+
OR CONDITIONS OF ANY KIND, either express or implied, including,
|
|
152
|
+
without limitation, any warranties or conditions of TITLE,
|
|
153
|
+
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR
|
|
154
|
+
PURPOSE. You are solely responsible for determining the
|
|
155
|
+
appropriateness of using or redistributing the Work and assume any
|
|
156
|
+
risks associated with Your exercise of permissions under this License.
|
|
157
|
+
|
|
158
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
159
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
160
|
+
unless required by applicable law (such as deliberate and grossly
|
|
161
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
162
|
+
liable to You for damages, including any direct, indirect, special,
|
|
163
|
+
incidental, or consequential damages of any character arising as a
|
|
164
|
+
result of this License or out of the use or inability to use the
|
|
165
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
166
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
167
|
+
other commercial damages or losses), even if such Contributor
|
|
168
|
+
has been advised of the possibility of such damages.
|
|
169
|
+
|
|
170
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
171
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
172
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
173
|
+
or other liability obligations and/or rights consistent with this
|
|
174
|
+
License. However, in accepting such obligations, You may act only
|
|
175
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
176
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
177
|
+
defend, and hold each Contributor harmless for any liability
|
|
178
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
179
|
+
of your accepting any such warranty or additional liability.
|
|
180
|
+
|
|
181
|
+
END OF TERMS AND CONDITIONS
|
foundgine-3.4.0/PKG-INFO
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: foundgine
|
|
3
|
+
Version: 3.4.0
|
|
4
|
+
Summary: Thin MCP client for Foundgine (transport only)
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
12
|
+
Classifier: Typing :: Typed
|
|
13
|
+
Requires-Python: >=3.11
|
|
14
|
+
Requires-Dist: httpx<1,>=0.27
|
|
15
|
+
Provides-Extra: dev
|
|
16
|
+
Requires-Dist: mypy>=1.11; extra == 'dev'
|
|
17
|
+
Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
|
|
18
|
+
Requires-Dist: pytest-cov>=5; extra == 'dev'
|
|
19
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
20
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# foundgine-sdk (Python)
|
|
24
|
+
|
|
25
|
+
A thin Python client for Foundgine MCP and Temporal workflow HTTP transports.
|
|
26
|
+
|
|
27
|
+
> Part of the Foundgine repository. This client talks to a running Foundgine server (the .NET or Java implementation hosting the MCP and Temporal endpoints); it does not contain the semantic runtime. See the [client SDK overview](../../docs/wiki/client-sdks.md) and the [source layout](../README.md).
|
|
28
|
+
|
|
29
|
+
Requires Python 3.11+ and `httpx`.
|
|
30
|
+
|
|
31
|
+
## Local install and checks
|
|
32
|
+
|
|
33
|
+
Run from `src/python/`:
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
pip install -e ".[dev]"
|
|
37
|
+
ruff check . && mypy && pytest
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The project metadata names the distribution `foundgine-sdk`. This repository snapshot documents the editable source install; it does not claim that a PyPI release is available.
|
|
41
|
+
|
|
42
|
+
## MCP client
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
import asyncio
|
|
46
|
+
import json
|
|
47
|
+
from foundgine import FoundgineClient
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
async def main() -> None:
|
|
51
|
+
async with FoundgineClient("https://example.invalid", token=lambda: "tok") as client:
|
|
52
|
+
tools = await client.list_capabilities()
|
|
53
|
+
# Query tools take one `intentJson` string; names come from foundgine_capabilities.
|
|
54
|
+
intent = {"rootEntity": "Customer", "selections": [{"field": "Name"}], "limit": 20}
|
|
55
|
+
result = await client.execute("foundgine_query_semantic", {"intentJson": json.dumps(intent)})
|
|
56
|
+
print([t.name for t in tools], result.content, result.is_error)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
asyncio.run(main())
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
`token` may be a string or a sync/async callable; it is resolved for every request. Redirects are not followed. If you pass `http_client=`, the SDK never closes it. Without one, the SDK creates its own client with explicit timeouts (connect 10 s, read 60 s; `DEFAULT_TIMEOUT`) because httpx's 5 s default would break slow tool calls.
|
|
63
|
+
|
|
64
|
+
### Synchronous client (scripts and notebooks)
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from foundgine import FoundgineSyncClient
|
|
68
|
+
|
|
69
|
+
with FoundgineSyncClient("https://example.invalid", token="tok") as client:
|
|
70
|
+
print([t.name for t in client.list_capabilities()])
|
|
71
|
+
print(client.workflows.wait_for_completion("order-approval", "order-1042", timeout=60).temporal_status)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Same methods and exceptions as the async client, run on a private event-loop thread (so it also works inside Jupyter). `watch` and the `cancel` event are async-only; Ctrl-C cancels the in-flight call. `notifications()` is a blocking generator: wrap it in `contextlib.closing` if you stop early.
|
|
75
|
+
|
|
76
|
+
## Notifications
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
import asyncio
|
|
80
|
+
import contextlib
|
|
81
|
+
|
|
82
|
+
cancel = asyncio.Event()
|
|
83
|
+
async with contextlib.aclosing(client.notifications(cancel=cancel)) as stream:
|
|
84
|
+
async for message in stream:
|
|
85
|
+
print(message)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The stream resumes using `Last-Event-ID` after the server closes it. Setting `cancel` ends the iteration cleanly. If you stop early, close the iterator (`contextlib.aclosing`, as above) so the server's single stream slot is released. There is no read timeout on the stream (heartbeats keep it alive).
|
|
89
|
+
|
|
90
|
+
## Temporal workflows
|
|
91
|
+
|
|
92
|
+
The workflow client follows the HTTP routes exposed by Foundgine Temporal:
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
started, watch = await client.workflows.start_and_watch(
|
|
96
|
+
"order-approval", "order-1042", {"orderId": "order-1042"}, interval=1.0, timeout=120.0
|
|
97
|
+
)
|
|
98
|
+
print(started.workflow_id)
|
|
99
|
+
async for status in watch.updates():
|
|
100
|
+
print(status.temporal_status)
|
|
101
|
+
final = await watch.done
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
The catalog can also be inspected before starting work:
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
names = await client.workflows.processes()
|
|
108
|
+
definition = await client.workflows.describe(names[0])
|
|
109
|
+
print([(step.name, step.requires_approval) for step in definition.steps])
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Also available: `processes`, `describe`, `start`, `status`, `decide`, `cancel`, `wait_for_completion`, and `watch`. Catalog descriptions expose safe step metadata only; internal operation identifiers are not returned by the server. `watch()` returns immediately and must be called inside a running event loop. `updates()` replays distinct observed states to late consumers. `stop()` aborts polling (`done` and `updates()` then raise `FoundgineAbortError`); `async with watch:` stops it on exit. `on_update` and `on_error` may be plain functions or coroutine functions, and their failures never kill the poll loop. Process and business-key path segments are percent-encoded. `decide` has no caller-identity argument: the server stamps the decision subject from its trusted security context.
|
|
113
|
+
|
|
114
|
+
## Deliberate differences from `@foundgine/typescript`
|
|
115
|
+
|
|
116
|
+
| TypeScript | Python | Why |
|
|
117
|
+
|---|---|---|
|
|
118
|
+
| `camelCase`, `intervalMs`, `timeoutMs`, `notFoundGraceMs`, `reconnectDelayMs` | `snake_case`, `interval`, `timeout`, `not_found_grace`, `reconnect_delay` in **seconds** | Python convention |
|
|
119
|
+
| `AbortSignal` (`signal`) | optional `asyncio.Event` named `cancel`; task cancellation also works and sends `notifications/cancelled` | no `AbortSignal` in Python |
|
|
120
|
+
| `new FoundgineClient({ baseUrl })` | `FoundgineClient(base_url)`, usable as `async with` | idiom |
|
|
121
|
+
| `watch()` object literal | `WorkflowWatch` class (`done` is an `asyncio.Task`) | idiom |
|
|
122
|
+
| `watch.stop()` after finishing makes `updates()` throw | `stop()` is a no-op once finished | avoids a completed watch turning into an error |
|
|
123
|
+
| abort during a status poll is counted as a poll error and reaches `onError` | `FoundgineAbortError` is re-raised immediately | an abort is not a failure |
|
|
124
|
+
| workflow transport failures surface as raw `fetch` errors | wrapped in `FoundgineError` (as MCP calls already are) | consistent error surface |
|
|
125
|
+
| 400-without-session CORS hint | not applicable | no browser CORS in Python |
|
|
126
|
+
|
|
127
|
+
## Status and known limits
|
|
128
|
+
|
|
129
|
+
Implemented and tested: typed errors, SSE parser (including shared conformance vectors), MCP session initialization (once, even under concurrency), JSON-RPC requests, paged `list_capabilities`, `execute`, cancellation, resumable notification streaming, Temporal start/status/decision/cancel routes, `wait_for_completion`, `watch`, `start_and_watch`, and the workflow catalog (`processes()`, `describe()`). As in `@foundgine/typescript`, `watch` retries other polling errors up to `max_consecutive_errors`, but a 401 is fatal at once.
|
|
130
|
+
|
|
131
|
+
Not yet done or verified: an integration test against a real Foundgine server. Developed and tested on Python 3.12; CI covers 3.11–3.14. `tests/test_conformance.py` runs the shared vectors in `src/conformance`; they skip locally when absent and fail when `CI` is set. This is a development package, not a release-ready SDK.
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
# foundgine-sdk (Python)
|
|
2
|
+
|
|
3
|
+
A thin Python client for Foundgine MCP and Temporal workflow HTTP transports.
|
|
4
|
+
|
|
5
|
+
> Part of the Foundgine repository. This client talks to a running Foundgine server (the .NET or Java implementation hosting the MCP and Temporal endpoints); it does not contain the semantic runtime. See the [client SDK overview](../../docs/wiki/client-sdks.md) and the [source layout](../README.md).
|
|
6
|
+
|
|
7
|
+
Requires Python 3.11+ and `httpx`.
|
|
8
|
+
|
|
9
|
+
## Local install and checks
|
|
10
|
+
|
|
11
|
+
Run from `src/python/`:
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
pip install -e ".[dev]"
|
|
15
|
+
ruff check . && mypy && pytest
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The project metadata names the distribution `foundgine-sdk`. This repository snapshot documents the editable source install; it does not claim that a PyPI release is available.
|
|
19
|
+
|
|
20
|
+
## MCP client
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
import asyncio
|
|
24
|
+
import json
|
|
25
|
+
from foundgine import FoundgineClient
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
async def main() -> None:
|
|
29
|
+
async with FoundgineClient("https://example.invalid", token=lambda: "tok") as client:
|
|
30
|
+
tools = await client.list_capabilities()
|
|
31
|
+
# Query tools take one `intentJson` string; names come from foundgine_capabilities.
|
|
32
|
+
intent = {"rootEntity": "Customer", "selections": [{"field": "Name"}], "limit": 20}
|
|
33
|
+
result = await client.execute("foundgine_query_semantic", {"intentJson": json.dumps(intent)})
|
|
34
|
+
print([t.name for t in tools], result.content, result.is_error)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
asyncio.run(main())
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
`token` may be a string or a sync/async callable; it is resolved for every request. Redirects are not followed. If you pass `http_client=`, the SDK never closes it. Without one, the SDK creates its own client with explicit timeouts (connect 10 s, read 60 s; `DEFAULT_TIMEOUT`) because httpx's 5 s default would break slow tool calls.
|
|
41
|
+
|
|
42
|
+
### Synchronous client (scripts and notebooks)
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
from foundgine import FoundgineSyncClient
|
|
46
|
+
|
|
47
|
+
with FoundgineSyncClient("https://example.invalid", token="tok") as client:
|
|
48
|
+
print([t.name for t in client.list_capabilities()])
|
|
49
|
+
print(client.workflows.wait_for_completion("order-approval", "order-1042", timeout=60).temporal_status)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Same methods and exceptions as the async client, run on a private event-loop thread (so it also works inside Jupyter). `watch` and the `cancel` event are async-only; Ctrl-C cancels the in-flight call. `notifications()` is a blocking generator: wrap it in `contextlib.closing` if you stop early.
|
|
53
|
+
|
|
54
|
+
## Notifications
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
import asyncio
|
|
58
|
+
import contextlib
|
|
59
|
+
|
|
60
|
+
cancel = asyncio.Event()
|
|
61
|
+
async with contextlib.aclosing(client.notifications(cancel=cancel)) as stream:
|
|
62
|
+
async for message in stream:
|
|
63
|
+
print(message)
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
The stream resumes using `Last-Event-ID` after the server closes it. Setting `cancel` ends the iteration cleanly. If you stop early, close the iterator (`contextlib.aclosing`, as above) so the server's single stream slot is released. There is no read timeout on the stream (heartbeats keep it alive).
|
|
67
|
+
|
|
68
|
+
## Temporal workflows
|
|
69
|
+
|
|
70
|
+
The workflow client follows the HTTP routes exposed by Foundgine Temporal:
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
started, watch = await client.workflows.start_and_watch(
|
|
74
|
+
"order-approval", "order-1042", {"orderId": "order-1042"}, interval=1.0, timeout=120.0
|
|
75
|
+
)
|
|
76
|
+
print(started.workflow_id)
|
|
77
|
+
async for status in watch.updates():
|
|
78
|
+
print(status.temporal_status)
|
|
79
|
+
final = await watch.done
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The catalog can also be inspected before starting work:
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
names = await client.workflows.processes()
|
|
86
|
+
definition = await client.workflows.describe(names[0])
|
|
87
|
+
print([(step.name, step.requires_approval) for step in definition.steps])
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Also available: `processes`, `describe`, `start`, `status`, `decide`, `cancel`, `wait_for_completion`, and `watch`. Catalog descriptions expose safe step metadata only; internal operation identifiers are not returned by the server. `watch()` returns immediately and must be called inside a running event loop. `updates()` replays distinct observed states to late consumers. `stop()` aborts polling (`done` and `updates()` then raise `FoundgineAbortError`); `async with watch:` stops it on exit. `on_update` and `on_error` may be plain functions or coroutine functions, and their failures never kill the poll loop. Process and business-key path segments are percent-encoded. `decide` has no caller-identity argument: the server stamps the decision subject from its trusted security context.
|
|
91
|
+
|
|
92
|
+
## Deliberate differences from `@foundgine/typescript`
|
|
93
|
+
|
|
94
|
+
| TypeScript | Python | Why |
|
|
95
|
+
|---|---|---|
|
|
96
|
+
| `camelCase`, `intervalMs`, `timeoutMs`, `notFoundGraceMs`, `reconnectDelayMs` | `snake_case`, `interval`, `timeout`, `not_found_grace`, `reconnect_delay` in **seconds** | Python convention |
|
|
97
|
+
| `AbortSignal` (`signal`) | optional `asyncio.Event` named `cancel`; task cancellation also works and sends `notifications/cancelled` | no `AbortSignal` in Python |
|
|
98
|
+
| `new FoundgineClient({ baseUrl })` | `FoundgineClient(base_url)`, usable as `async with` | idiom |
|
|
99
|
+
| `watch()` object literal | `WorkflowWatch` class (`done` is an `asyncio.Task`) | idiom |
|
|
100
|
+
| `watch.stop()` after finishing makes `updates()` throw | `stop()` is a no-op once finished | avoids a completed watch turning into an error |
|
|
101
|
+
| abort during a status poll is counted as a poll error and reaches `onError` | `FoundgineAbortError` is re-raised immediately | an abort is not a failure |
|
|
102
|
+
| workflow transport failures surface as raw `fetch` errors | wrapped in `FoundgineError` (as MCP calls already are) | consistent error surface |
|
|
103
|
+
| 400-without-session CORS hint | not applicable | no browser CORS in Python |
|
|
104
|
+
|
|
105
|
+
## Status and known limits
|
|
106
|
+
|
|
107
|
+
Implemented and tested: typed errors, SSE parser (including shared conformance vectors), MCP session initialization (once, even under concurrency), JSON-RPC requests, paged `list_capabilities`, `execute`, cancellation, resumable notification streaming, Temporal start/status/decision/cancel routes, `wait_for_completion`, `watch`, `start_and_watch`, and the workflow catalog (`processes()`, `describe()`). As in `@foundgine/typescript`, `watch` retries other polling errors up to `max_consecutive_errors`, but a 401 is fatal at once.
|
|
108
|
+
|
|
109
|
+
Not yet done or verified: an integration test against a real Foundgine server. Developed and tested on Python 3.12; CI covers 3.11–3.14. `tests/test_conformance.py` runs the shared vectors in `src/conformance`; they skip locally when absent and fail when `CI` is set. This is a development package, not a release-ready SDK.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.25"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "foundgine"
|
|
7
|
+
version = "3.4.0"
|
|
8
|
+
description = "Thin MCP client for Foundgine (transport only)"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "Apache-2.0"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
dependencies = [
|
|
14
|
+
"httpx>=0.27,<1",
|
|
15
|
+
]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Programming Language :: Python :: 3.11",
|
|
19
|
+
"Programming Language :: Python :: 3.12",
|
|
20
|
+
"Programming Language :: Python :: 3.13",
|
|
21
|
+
"Programming Language :: Python :: 3.14",
|
|
22
|
+
"Typing :: Typed",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[project.optional-dependencies]
|
|
26
|
+
dev = [
|
|
27
|
+
"pytest>=8",
|
|
28
|
+
"pytest-asyncio>=0.24",
|
|
29
|
+
"pytest-cov>=5",
|
|
30
|
+
"ruff>=0.6",
|
|
31
|
+
"mypy>=1.11",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[tool.hatch.build.targets.wheel]
|
|
35
|
+
packages = ["src/foundgine"]
|
|
36
|
+
|
|
37
|
+
[tool.pytest.ini_options]
|
|
38
|
+
testpaths = ["tests"]
|
|
39
|
+
asyncio_mode = "auto"
|
|
40
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
41
|
+
addopts = "-ra"
|
|
42
|
+
|
|
43
|
+
[tool.ruff]
|
|
44
|
+
line-length = 120
|
|
45
|
+
target-version = "py311"
|
|
46
|
+
|
|
47
|
+
[tool.ruff.lint]
|
|
48
|
+
select = ["E", "F", "I", "B", "UP", "ASYNC", "RUF"]
|
|
49
|
+
|
|
50
|
+
[tool.mypy]
|
|
51
|
+
strict = true
|
|
52
|
+
python_version = "3.11"
|
|
53
|
+
files = ["src", "tests"]
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"""Python SDK for Foundgine (transport only). API aligned with @foundgine/typescript."""
|
|
2
|
+
|
|
3
|
+
from .client import DEFAULT_TIMEOUT, FoundgineClient, Tool, ToolResult
|
|
4
|
+
from .errors import (
|
|
5
|
+
FoundgineAbortError,
|
|
6
|
+
FoundgineError,
|
|
7
|
+
FoundgineHttpError,
|
|
8
|
+
FoundgineResyncRequiredError,
|
|
9
|
+
FoundgineRpcError,
|
|
10
|
+
FoundgineSessionExpiredError,
|
|
11
|
+
FoundgineWatchTimeoutError,
|
|
12
|
+
)
|
|
13
|
+
from .http import TokenProvider
|
|
14
|
+
from .mcp import DEFAULT_PROTOCOL_VERSION, McpSession
|
|
15
|
+
from .sse import SseEvent, SseParser
|
|
16
|
+
from .sync import FoundgineSyncClient, SyncWorkflowClient
|
|
17
|
+
from .workflows import (
|
|
18
|
+
StartAndWatch,
|
|
19
|
+
WorkflowClient,
|
|
20
|
+
WorkflowProcessDescription,
|
|
21
|
+
WorkflowStartResult,
|
|
22
|
+
WorkflowStatus,
|
|
23
|
+
WorkflowStepDescription,
|
|
24
|
+
WorkflowWatch,
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
__version__ = "3.4.0"
|
|
28
|
+
|
|
29
|
+
__all__ = [
|
|
30
|
+
"DEFAULT_PROTOCOL_VERSION",
|
|
31
|
+
"DEFAULT_TIMEOUT",
|
|
32
|
+
"FoundgineAbortError",
|
|
33
|
+
"FoundgineClient",
|
|
34
|
+
"FoundgineError",
|
|
35
|
+
"FoundgineHttpError",
|
|
36
|
+
"FoundgineResyncRequiredError",
|
|
37
|
+
"FoundgineRpcError",
|
|
38
|
+
"FoundgineSessionExpiredError",
|
|
39
|
+
"FoundgineSyncClient",
|
|
40
|
+
"FoundgineWatchTimeoutError",
|
|
41
|
+
"McpSession",
|
|
42
|
+
"SseEvent",
|
|
43
|
+
"SseParser",
|
|
44
|
+
"StartAndWatch",
|
|
45
|
+
"SyncWorkflowClient",
|
|
46
|
+
"TokenProvider",
|
|
47
|
+
"Tool",
|
|
48
|
+
"ToolResult",
|
|
49
|
+
"WorkflowClient",
|
|
50
|
+
"WorkflowProcessDescription",
|
|
51
|
+
"WorkflowStartResult",
|
|
52
|
+
"WorkflowStatus",
|
|
53
|
+
"WorkflowStepDescription",
|
|
54
|
+
"WorkflowWatch",
|
|
55
|
+
"__version__",
|
|
56
|
+
]
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""Private HTTP helpers shared by the MCP and workflow clients."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import inspect
|
|
6
|
+
import json
|
|
7
|
+
from collections.abc import Awaitable, Callable
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
import httpx
|
|
11
|
+
|
|
12
|
+
from .errors import FoundgineHttpError
|
|
13
|
+
|
|
14
|
+
TokenProvider = str | Callable[[], str | Awaitable[str | None] | None] | None
|
|
15
|
+
DEFAULT_TIMEOUT = httpx.Timeout(connect=10.0, read=60.0, write=60.0, pool=10.0)
|
|
16
|
+
STREAM_TIMEOUT = httpx.Timeout(connect=10.0, read=None, write=60.0, pool=10.0)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
async def resolve_token(token: TokenProvider) -> str | None:
|
|
20
|
+
"""Resolve a fixed, synchronous, or asynchronous bearer-token provider."""
|
|
21
|
+
value: Any = token() if callable(token) else token
|
|
22
|
+
if inspect.isawaitable(value):
|
|
23
|
+
value = await value
|
|
24
|
+
return value if isinstance(value, str) and value else None
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def join_url(base_url: str, path: str) -> str:
|
|
28
|
+
"""Join a base URL and absolute-or-relative path without duplicate slashes."""
|
|
29
|
+
return base_url.rstrip("/") + "/" + path.lstrip("/")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def error_for(status: int, body: bytes, secret: str | None = None) -> FoundgineHttpError:
|
|
33
|
+
"""Create a safe HTTP error; request headers and credentials are never included."""
|
|
34
|
+
parsed: Any = None
|
|
35
|
+
detail: str | None = None
|
|
36
|
+
try:
|
|
37
|
+
parsed = json.loads(body.decode("utf-8", errors="replace")) if body else None
|
|
38
|
+
except ValueError:
|
|
39
|
+
pass
|
|
40
|
+
if isinstance(parsed, dict):
|
|
41
|
+
value = parsed.get("error")
|
|
42
|
+
if isinstance(value, str):
|
|
43
|
+
detail = value
|
|
44
|
+
elif isinstance(value, dict) and isinstance(value.get("message"), str):
|
|
45
|
+
detail = value["message"]
|
|
46
|
+
if detail is None and body and parsed is None:
|
|
47
|
+
detail = body.decode("utf-8", errors="replace")[:200].strip() or None
|
|
48
|
+
if detail and secret:
|
|
49
|
+
detail = detail.replace(secret, "[redacted]")
|
|
50
|
+
return FoundgineHttpError(status, f"HTTP {status}: {detail}" if detail else f"HTTP {status}", parsed)
|