funduq 0.0.1__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.
Files changed (95) hide show
  1. funduq-0.0.1/.gitignore +24 -0
  2. funduq-0.0.1/LICENSE +201 -0
  3. funduq-0.0.1/PKG-INFO +80 -0
  4. funduq-0.0.1/README.md +47 -0
  5. funduq-0.0.1/alembic.ini +52 -0
  6. funduq-0.0.1/funduq/__init__.py +7 -0
  7. funduq-0.0.1/funduq/agui.py +66 -0
  8. funduq-0.0.1/funduq/agui_reduce.py +68 -0
  9. funduq-0.0.1/funduq/alembic/env.py +81 -0
  10. funduq-0.0.1/funduq/alembic/script.py.mako +28 -0
  11. funduq-0.0.1/funduq/alembic/versions/20260818_ff342e6c6b85_initial_schema.py +122 -0
  12. funduq-0.0.1/funduq/alembic/versions/20260821_a11c3b7d42e9_head_keys.py +31 -0
  13. funduq-0.0.1/funduq/alembic/versions/20260823_c4d9e17b52aa_offering_status.py +89 -0
  14. funduq-0.0.1/funduq/alembic/versions/20260825_e7b3a94c1f60_runs_actor_chain.py +39 -0
  15. funduq-0.0.1/funduq/broker.py +917 -0
  16. funduq-0.0.1/funduq/changes.py +23 -0
  17. funduq-0.0.1/funduq/config.py +38 -0
  18. funduq-0.0.1/funduq/core.py +1142 -0
  19. funduq-0.0.1/funduq/db_schema.py +9 -0
  20. funduq-0.0.1/funduq/doors.py +387 -0
  21. funduq-0.0.1/funduq/errors.py +130 -0
  22. funduq-0.0.1/funduq/handlers.py +242 -0
  23. funduq-0.0.1/funduq/identity.py +231 -0
  24. funduq-0.0.1/funduq/ids.py +5 -0
  25. funduq-0.0.1/funduq/kyok.py +222 -0
  26. funduq-0.0.1/funduq/live_roster.py +52 -0
  27. funduq-0.0.1/funduq/migrate.py +46 -0
  28. funduq-0.0.1/funduq/models.py +103 -0
  29. funduq-0.0.1/funduq/pause.py +103 -0
  30. funduq-0.0.1/funduq/props.py +87 -0
  31. funduq-0.0.1/funduq/protocols/__init__.py +1 -0
  32. funduq-0.0.1/funduq/protocols/a2a.py +512 -0
  33. funduq-0.0.1/funduq/protocols/a2a_translate.py +248 -0
  34. funduq-0.0.1/funduq/protocols/agui.py +198 -0
  35. funduq-0.0.1/funduq/protocols/kyok.py +251 -0
  36. funduq-0.0.1/funduq/py.typed +0 -0
  37. funduq-0.0.1/funduq/repo.py +904 -0
  38. funduq-0.0.1/funduq/schema.py +180 -0
  39. funduq-0.0.1/pyproject.toml +125 -0
  40. funduq-0.0.1/tests/__init__.py +1 -0
  41. funduq-0.0.1/tests/conftest.py +226 -0
  42. funduq-0.0.1/tests/contract_surface.py +173 -0
  43. funduq-0.0.1/tests/real_deferring_stream.json +193 -0
  44. funduq-0.0.1/tests/test_a2a_conformance.py +137 -0
  45. funduq-0.0.1/tests/test_a2a_spec_methods.py +309 -0
  46. funduq-0.0.1/tests/test_a2a_translate.py +256 -0
  47. funduq-0.0.1/tests/test_agent_card_from_handle.py +100 -0
  48. funduq-0.0.1/tests/test_agui_adapter.py +183 -0
  49. funduq-0.0.1/tests/test_agui_ids.py +26 -0
  50. funduq-0.0.1/tests/test_agui_reduce.py +84 -0
  51. funduq-0.0.1/tests/test_agui_reduce_persistence.py +116 -0
  52. funduq-0.0.1/tests/test_attach_proof.py +152 -0
  53. funduq-0.0.1/tests/test_broker.py +151 -0
  54. funduq-0.0.1/tests/test_broker_delivers.py +782 -0
  55. funduq-0.0.1/tests/test_change_hook.py +170 -0
  56. funduq-0.0.1/tests/test_contract_revision.py +93 -0
  57. funduq-0.0.1/tests/test_contract_vectors.py +142 -0
  58. funduq-0.0.1/tests/test_conversation_queue.py +588 -0
  59. funduq-0.0.1/tests/test_core_is_network_free.py +177 -0
  60. funduq-0.0.1/tests/test_core_is_sdk_free.py +54 -0
  61. funduq-0.0.1/tests/test_core_quotes_the_protocols.py +71 -0
  62. funduq-0.0.1/tests/test_deferred_call_round_trip.py +226 -0
  63. funduq-0.0.1/tests/test_delegation_chain.py +81 -0
  64. funduq-0.0.1/tests/test_delete_agent.py +135 -0
  65. funduq-0.0.1/tests/test_event_path.py +86 -0
  66. funduq-0.0.1/tests/test_facade.py +473 -0
  67. funduq-0.0.1/tests/test_health.py +132 -0
  68. funduq-0.0.1/tests/test_health_check.py +146 -0
  69. funduq-0.0.1/tests/test_identity.py +106 -0
  70. funduq-0.0.1/tests/test_in_process_delegation.py +197 -0
  71. funduq-0.0.1/tests/test_in_process_identity.py +88 -0
  72. funduq-0.0.1/tests/test_kyok.py +259 -0
  73. funduq-0.0.1/tests/test_link_thread_messages_resume.py +97 -0
  74. funduq-0.0.1/tests/test_llm_provider_drives_kyok.py +663 -0
  75. funduq-0.0.1/tests/test_llm_provider_sdk_contract.py +65 -0
  76. funduq-0.0.1/tests/test_migrate_entry.py +15 -0
  77. funduq-0.0.1/tests/test_multi_agent_provider.py +86 -0
  78. funduq-0.0.1/tests/test_mutual_identity.py +225 -0
  79. funduq-0.0.1/tests/test_packages_are_publishable.py +100 -0
  80. funduq-0.0.1/tests/test_pause.py +59 -0
  81. funduq-0.0.1/tests/test_pause_resume.py +258 -0
  82. funduq-0.0.1/tests/test_presenter_check.py +119 -0
  83. funduq-0.0.1/tests/test_provider_sdk_contract.py +147 -0
  84. funduq-0.0.1/tests/test_provider_sdk_drives_funduq.py +161 -0
  85. funduq-0.0.1/tests/test_query_models.py +105 -0
  86. funduq-0.0.1/tests/test_reconnect_replaces.py +76 -0
  87. funduq-0.0.1/tests/test_repo_ids.py +106 -0
  88. funduq-0.0.1/tests/test_repo_registration.py +180 -0
  89. funduq-0.0.1/tests/test_reserved_metadata.py +87 -0
  90. funduq-0.0.1/tests/test_responsibility_chains.py +474 -0
  91. funduq-0.0.1/tests/test_run_failure_is_reported.py +488 -0
  92. funduq-0.0.1/tests/test_run_keeps_its_chain.py +129 -0
  93. funduq-0.0.1/tests/test_types_are_shipped.py +32 -0
  94. funduq-0.0.1/tests/test_wire_loopback.py +180 -0
  95. funduq-0.0.1/uv.lock +1382 -0
@@ -0,0 +1,24 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.pyc
4
+ .env
5
+
6
+ # Local SQLite database files — funduq's zero-config default backend writes
7
+ # ./funduq.db (plus -wal/-shm sidecars) when FUNDUQ_DATABASE_URL is unset. Local
8
+ # state, never commit; a real deployment uses Postgres instead.
9
+ *.db
10
+ *.db-wal
11
+ *.db-shm
12
+ *.sqlite
13
+ *.sqlite3
14
+
15
+ # Provider identity keys (see funduq_agent_sdk/identity.py) — a credential,
16
+ # never commit one.
17
+ *.key
18
+ funduq_identity.key
19
+
20
+ # Dev-only TLS cert/key generated by scripts/gen_dev_tls_cert.py.
21
+ dev_cert.pem
22
+ dev_key.pem
23
+
24
+ .pytest_cache/
funduq-0.0.1/LICENSE ADDED
@@ -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
44
+ purposes of this License, Derivative Works shall not include works
45
+ that remain separable from, or merely link (or bind by name) to the
46
+ interfaces of, the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including the
49
+ 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
141
+ the 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 2026 funduq contributors
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.
funduq-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,80 @@
1
+ Metadata-Version: 2.5
2
+ Name: funduq
3
+ Version: 0.0.1
4
+ Summary: funduq core — the network-free library: agents, threads, runs, and the protocol adapters
5
+ Project-URL: Homepage, https://github.com/hukaichun/funduq
6
+ Project-URL: Documentation, https://hukaichun.github.io/funduq/
7
+ Project-URL: Source, https://github.com/hukaichun/funduq
8
+ Project-URL: Changelog, https://github.com/hukaichun/funduq/blob/main/docs/contract-changelog.md
9
+ Project-URL: Issues, https://github.com/hukaichun/funduq/issues
10
+ Author: Kai-Chun Hu
11
+ License-Expression: Apache-2.0
12
+ License-File: LICENSE
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Topic :: Software Development :: Libraries
18
+ Classifier: Typing :: Typed
19
+ Requires-Python: >=3.12
20
+ Requires-Dist: a2a-sdk<2,>=1.1
21
+ Requires-Dist: ag-ui-protocol>=0.1.19
22
+ Requires-Dist: aiosqlite>=0.20
23
+ Requires-Dist: alembic>=1.13
24
+ Requires-Dist: cryptography>=42.0
25
+ Requires-Dist: funduq-contract<0.1,>=0.0.1
26
+ Requires-Dist: openai>=1.50
27
+ Requires-Dist: pydantic-settings>=2.6
28
+ Requires-Dist: pyjwt>=2.9
29
+ Requires-Dist: sqlalchemy[asyncio]>=2.0
30
+ Provides-Extra: postgres
31
+ Requires-Dist: psycopg[binary,pool]>=3.2; extra == 'postgres'
32
+ Description-Content-Type: text/markdown
33
+
34
+ # funduq
35
+
36
+ The network-free core: agents, threads, runs, dispatch, and the protocol
37
+ adapters. A library you embed, not a server you run.
38
+
39
+ ```
40
+ pip install funduq # SQLite, the zero-config default
41
+ pip install "funduq[postgres]" # for a real multi-writer deployment
42
+ ```
43
+
44
+ **This package implements no transport: its code neither listens nor dials.**
45
+ Serving — an HTTP or gRPC binding for the AG-UI and A2A doors — lives
46
+ downstream, in [funduq-server](https://github.com/hukaichun/funduq). What is
47
+ here is everything that decides: the roster, the run record, dispatch to a
48
+ connected provider, and translation at the doors.
49
+
50
+ Two protocols are quoted rather than transcribed. AG-UI shapes come from
51
+ `ag-ui-protocol` and A2A's from `a2a-sdk`, including the method names, so a
52
+ protocol rename fails at import here instead of at a client six months later.
53
+
54
+ ## What you get
55
+
56
+ - **Agents, threads and runs** — a run is one turn of an agent's loop, with
57
+ its identity held across a pause for a human, so work can span hours.
58
+ - **Dispatch** — runs offered to whichever provider is serving, per-thread
59
+ ordering, declared concurrency, and quality counters for what funduq can
60
+ see from where it stands.
61
+ - **Doors** — AG-UI and A2A adapters over one seat, so which protocol a
62
+ request arrived by changes nothing about how it is decided.
63
+ - **Identity** — providers prove a key to connect, callers may carry an
64
+ actor chain, and neither is optional for being in-process.
65
+
66
+ ## Read before deploying
67
+
68
+ [What a deployment has to know](https://hukaichun.github.io/funduq/operational-limits/)
69
+ — in particular that **core's caller doors are not independently safe**:
70
+ verifying a chain is not authenticating a caller, and a door has no live
71
+ channel to do the second.
72
+
73
+ ## Its companions
74
+
75
+ | | |
76
+ |---|---|
77
+ | [`funduq-contract`](https://pypi.org/project/funduq-contract/) | the bytes both sides sign — core depends on it, and so does the SDK |
78
+ | [`funduq-provider-sdk`](https://pypi.org/project/funduq-provider-sdk/) | what a provider implements, with `[llm]` for completions |
79
+
80
+ Apache-2.0. Docs at <https://hukaichun.github.io/funduq/>.
funduq-0.0.1/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # funduq
2
+
3
+ The network-free core: agents, threads, runs, dispatch, and the protocol
4
+ adapters. A library you embed, not a server you run.
5
+
6
+ ```
7
+ pip install funduq # SQLite, the zero-config default
8
+ pip install "funduq[postgres]" # for a real multi-writer deployment
9
+ ```
10
+
11
+ **This package implements no transport: its code neither listens nor dials.**
12
+ Serving — an HTTP or gRPC binding for the AG-UI and A2A doors — lives
13
+ downstream, in [funduq-server](https://github.com/hukaichun/funduq). What is
14
+ here is everything that decides: the roster, the run record, dispatch to a
15
+ connected provider, and translation at the doors.
16
+
17
+ Two protocols are quoted rather than transcribed. AG-UI shapes come from
18
+ `ag-ui-protocol` and A2A's from `a2a-sdk`, including the method names, so a
19
+ protocol rename fails at import here instead of at a client six months later.
20
+
21
+ ## What you get
22
+
23
+ - **Agents, threads and runs** — a run is one turn of an agent's loop, with
24
+ its identity held across a pause for a human, so work can span hours.
25
+ - **Dispatch** — runs offered to whichever provider is serving, per-thread
26
+ ordering, declared concurrency, and quality counters for what funduq can
27
+ see from where it stands.
28
+ - **Doors** — AG-UI and A2A adapters over one seat, so which protocol a
29
+ request arrived by changes nothing about how it is decided.
30
+ - **Identity** — providers prove a key to connect, callers may carry an
31
+ actor chain, and neither is optional for being in-process.
32
+
33
+ ## Read before deploying
34
+
35
+ [What a deployment has to know](https://hukaichun.github.io/funduq/operational-limits/)
36
+ — in particular that **core's caller doors are not independently safe**:
37
+ verifying a chain is not authenticating a caller, and a door has no live
38
+ channel to do the second.
39
+
40
+ ## Its companions
41
+
42
+ | | |
43
+ |---|---|
44
+ | [`funduq-contract`](https://pypi.org/project/funduq-contract/) | the bytes both sides sign — core depends on it, and so does the SDK |
45
+ | [`funduq-provider-sdk`](https://pypi.org/project/funduq-provider-sdk/) | what a provider implements, with `[llm]` for completions |
46
+
47
+ Apache-2.0. Docs at <https://hukaichun.github.io/funduq/>.
@@ -0,0 +1,52 @@
1
+ # Config for `alembic upgrade head`, run from funduq/ where this file lives
2
+ # (see docs/core-components/persistence.md for the schema tiers).
3
+ # sqlalchemy.url below is a placeholder — env.py overrides it with
4
+ # funduq.config.settings.database_url (FUNDUQ_DATABASE_URL) at runtime.
5
+
6
+ [alembic]
7
+ # The migration chain ships inside the package (funduq/alembic), so a
8
+ # pip-installed funduq builds and upgrades a database the same way this repo
9
+ # does — funduq.migrate.migrate() is the programmatic entry, this file only
10
+ # serves the CLI habit.
11
+ script_location = funduq:alembic
12
+ prepend_sys_path = .
13
+ path_separator = os
14
+ sqlalchemy.url = driver://user:pass@localhost/dbname
15
+ # Date-prefixed filenames so revisions sort chronologically at a glance
16
+ # (rev/down_revision inside each file is still the actual source of
17
+ # truth for ordering — this is purely for humans skimming the directory).
18
+ file_template = %%(year)d%%(month).2d%%(day).2d_%%(rev)s_%%(slug)s
19
+
20
+ [loggers]
21
+ keys = root,sqlalchemy,alembic
22
+
23
+ [handlers]
24
+ keys = console
25
+
26
+ [formatters]
27
+ keys = generic
28
+
29
+ [logger_root]
30
+ level = WARNING
31
+ handlers = console
32
+ qualname =
33
+
34
+ [logger_sqlalchemy]
35
+ level = WARNING
36
+ handlers =
37
+ qualname = sqlalchemy.engine
38
+
39
+ [logger_alembic]
40
+ level = INFO
41
+ handlers =
42
+ qualname = alembic
43
+
44
+ [handler_console]
45
+ class = StreamHandler
46
+ args = (sys.stderr,)
47
+ level = NOTSET
48
+ formatter = generic
49
+
50
+ [formatter_generic]
51
+ format = %(levelname)-5.5s [%(name)s] %(message)s
52
+ datefmt = %H:%M:%S
@@ -0,0 +1,7 @@
1
+ """`funduq.migrate` is deliberately both the submodule and, after this import,
2
+ the function bound over it — `funduq.migrate()` is the documented entry, and
3
+ `python -m funduq.migrate` keeps resolving to the module."""
4
+
5
+ from funduq.migrate import migrate
6
+
7
+ __all__ = ["migrate"]
@@ -0,0 +1,66 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any
4
+
5
+ from ag_ui.core import EventType, RunAgentInput
6
+ from pydantic import ValidationError
7
+
8
+ from funduq.ids import new_id
9
+
10
+ _MESSAGE_ID_EVENT_TYPES = {
11
+ EventType.TEXT_MESSAGE_START,
12
+ EventType.TEXT_MESSAGE_CONTENT,
13
+ EventType.TEXT_MESSAGE_CHUNK,
14
+ EventType.TEXT_MESSAGE_END,
15
+ }
16
+
17
+
18
+ def rewrite_message_ids(event: dict[str, Any], id_map: dict[str, str]) -> dict[str, Any]:
19
+ """Replaces a text-message event's `messageId` with a funduq-issued id, reusing the same
20
+ funduq id for every event sharing the original id (tracked in `id_map`). Events outside the
21
+ text-message-lifecycle types, or without a `messageId`, are returned unchanged."""
22
+ if event.get("type") not in _MESSAGE_ID_EVENT_TYPES:
23
+ return event
24
+ original = event.get("messageId")
25
+ if not original:
26
+ return event
27
+ funduq_id = id_map.setdefault(original, new_id("msg"))
28
+ return {**event, "messageId": funduq_id}
29
+
30
+
31
+ def build_run_agent_input(
32
+ thread_id: str,
33
+ run_id: str,
34
+ messages: list[dict[str, Any]],
35
+ state: Any = None,
36
+ tools: list[dict[str, Any]] | None = None,
37
+ context: list[dict[str, Any]] | None = None,
38
+ forwarded_props: Any = None,
39
+ resume: list[dict[str, Any]] | None = None,
40
+ parent_run_id: str | None = None,
41
+ ) -> dict[str, Any]:
42
+ """Builds and validates a wire-format AG-UI `RunAgentInput` dict from the given fields,
43
+ raising `ValueError` if the assembled input fails AG-UI's own validation.
44
+
45
+ `parent_run_id` is AG-UI's own field for placing another run's id on this
46
+ input. The id appearing a second time is the entire semantics: the caller
47
+ says this run follows that one. Whether it lands as a continuation or an
48
+ interjection is decided by the one fact funduq cannot hold — whether the
49
+ parent is still in flight — which the agent reads off its own loop."""
50
+ try:
51
+ model = RunAgentInput.model_validate(
52
+ {
53
+ "threadId": thread_id,
54
+ "runId": run_id,
55
+ "state": state,
56
+ "messages": messages,
57
+ "tools": tools or [],
58
+ "context": context or [],
59
+ "forwardedProps": forwarded_props,
60
+ "resume": resume,
61
+ "parentRunId": parent_run_id,
62
+ }
63
+ )
64
+ except ValidationError as e:
65
+ raise ValueError(f"invalid AG-UI run input: {e}") from e
66
+ return model.model_dump(mode="json", by_alias=True)
@@ -0,0 +1,68 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any
4
+
5
+ from ag_ui.core import EventType
6
+
7
+
8
+ def reduce_events_to_messages(events: list[dict[str, Any]]) -> list[dict[str, Any]]:
9
+ """Folds a stream of AG-UI events into the thread-history messages they represent, in the
10
+ order each message first appeared. Text-message events accumulate into one assistant
11
+ message per `messageId`; tool-call events accumulate into the parent message's `toolCalls`
12
+ (or their own standalone message if there is no parent); a `TOOL_CALL_RESULT` becomes its
13
+ own tool message. Lifecycle and state events (e.g. `RUN_STARTED`, `STATE_DELTA`) produce
14
+ nothing."""
15
+ messages: dict[str, dict[str, Any]] = {}
16
+ order: list[str] = []
17
+ tool_call_parent: dict[str, str] = {}
18
+
19
+ def assistant_message(message_id: str, role: str = "assistant") -> dict[str, Any]:
20
+ if message_id not in messages:
21
+ messages[message_id] = {"id": message_id, "role": role, "content": ""}
22
+ order.append(message_id)
23
+ return messages[message_id]
24
+
25
+ for event in events:
26
+ etype = event.get("type")
27
+
28
+ if etype == EventType.TEXT_MESSAGE_START:
29
+ assistant_message(event["messageId"], event.get("role", "assistant"))
30
+
31
+ elif etype == EventType.TEXT_MESSAGE_CONTENT:
32
+ assistant_message(event["messageId"])["content"] += event.get("delta", "")
33
+
34
+ elif etype == EventType.TOOL_CALL_START:
35
+ tool_call_id = event["toolCallId"]
36
+ parent_id = event.get("parentMessageId") or tool_call_id
37
+ tool_call_parent[tool_call_id] = parent_id
38
+ msg = assistant_message(parent_id)
39
+ msg.setdefault("toolCalls", []).append(
40
+ {
41
+ "id": tool_call_id,
42
+ "type": "function",
43
+ "function": {"name": event["toolCallName"], "arguments": ""},
44
+ }
45
+ )
46
+
47
+ elif etype == EventType.TOOL_CALL_ARGS:
48
+ tool_call_id = event["toolCallId"]
49
+ parent_id = tool_call_parent.get(tool_call_id)
50
+ if parent_id is None:
51
+ continue
52
+ for tool_call in messages[parent_id].get("toolCalls", []):
53
+ if tool_call["id"] == tool_call_id:
54
+ tool_call["function"]["arguments"] += event.get("delta", "")
55
+ break
56
+
57
+ elif etype == EventType.TOOL_CALL_RESULT:
58
+ message_id = event["messageId"]
59
+ messages[message_id] = {
60
+ "id": message_id,
61
+ "role": "tool",
62
+ "content": event.get("content", ""),
63
+ "toolCallId": event["toolCallId"],
64
+ }
65
+ order.append(message_id)
66
+
67
+
68
+ return [messages[message_id] for message_id in order]
@@ -0,0 +1,81 @@
1
+ import os
2
+ from logging.config import fileConfig
3
+
4
+ from sqlalchemy import engine_from_config
5
+ from sqlalchemy import pool
6
+ from sqlalchemy import text
7
+ from sqlalchemy.engine import make_url
8
+
9
+ from alembic import context
10
+ from funduq.db_schema import DEFAULT_DATABASE_URL, DEFAULT_DB_SCHEMA, quoted_schema
11
+ from funduq.schema import metadata as funduq_metadata
12
+
13
+ config = context.config
14
+
15
+ if config.config_file_name is not None:
16
+ fileConfig(config.config_file_name, disable_existing_loggers=False)
17
+
18
+ target_metadata = funduq_metadata
19
+
20
+ database_url = config.attributes.get("funduq_database_url") or os.environ.get(
21
+ "FUNDUQ_DATABASE_URL", DEFAULT_DATABASE_URL
22
+ )
23
+
24
+ _url = make_url(database_url)
25
+ if _url.get_backend_name() == "sqlite" and _url.get_driver_name() == "aiosqlite":
26
+ database_url = _url.set(drivername="sqlite").render_as_string(hide_password=False)
27
+
28
+ config.set_main_option("sqlalchemy.url", database_url)
29
+
30
+ db_schema = config.attributes.get("funduq_db_schema") or os.environ.get(
31
+ "FUNDUQ_DB_SCHEMA", DEFAULT_DB_SCHEMA
32
+ )
33
+
34
+ if make_url(database_url).get_backend_name() != "postgresql":
35
+ db_schema = DEFAULT_DB_SCHEMA
36
+
37
+
38
+ def run_migrations_offline() -> None:
39
+ url = config.get_main_option("sqlalchemy.url")
40
+ context.configure(
41
+ url=url,
42
+ target_metadata=target_metadata,
43
+ literal_binds=True,
44
+ dialect_opts={"paramstyle": "named"},
45
+ version_table_schema=db_schema if db_schema != DEFAULT_DB_SCHEMA else None,
46
+ )
47
+
48
+ with context.begin_transaction():
49
+ if db_schema != DEFAULT_DB_SCHEMA:
50
+ context.execute(f"CREATE SCHEMA IF NOT EXISTS {quoted_schema(db_schema)}")
51
+ context.execute(f"SET search_path TO {quoted_schema(db_schema)}, public")
52
+ context.run_migrations()
53
+
54
+
55
+ def run_migrations_online() -> None:
56
+ connectable = engine_from_config(
57
+ config.get_section(config.config_ini_section, {}),
58
+ prefix="sqlalchemy.",
59
+ poolclass=pool.NullPool,
60
+ )
61
+
62
+ with connectable.connect() as connection:
63
+ if db_schema != DEFAULT_DB_SCHEMA:
64
+ connection.execute(text(f"CREATE SCHEMA IF NOT EXISTS {quoted_schema(db_schema)}"))
65
+ connection.execute(text(f"SET search_path TO {quoted_schema(db_schema)}, public"))
66
+ connection.commit()
67
+
68
+ context.configure(
69
+ connection=connection,
70
+ target_metadata=target_metadata,
71
+ version_table_schema=db_schema if db_schema != DEFAULT_DB_SCHEMA else None,
72
+ )
73
+
74
+ with context.begin_transaction():
75
+ context.run_migrations()
76
+
77
+
78
+ if context.is_offline_mode():
79
+ run_migrations_offline()
80
+ else:
81
+ run_migrations_online()
@@ -0,0 +1,28 @@
1
+ """${message}
2
+
3
+ Revision ID: ${up_revision}
4
+ Revises: ${down_revision | comma,n}
5
+ Create Date: ${create_date}
6
+
7
+ """
8
+ from typing import Sequence, Union
9
+
10
+ from alembic import op
11
+ import sqlalchemy as sa
12
+ ${imports if imports else ""}
13
+
14
+ # revision identifiers, used by Alembic.
15
+ revision: str = ${repr(up_revision)}
16
+ down_revision: Union[str, Sequence[str], None] = ${repr(down_revision)}
17
+ branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
18
+ depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
19
+
20
+
21
+ def upgrade() -> None:
22
+ """Upgrade schema."""
23
+ ${upgrades if upgrades else "pass"}
24
+
25
+
26
+ def downgrade() -> None:
27
+ """Downgrade schema."""
28
+ ${downgrades if downgrades else "pass"}