tai42-toolbox 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.
Files changed (40) hide show
  1. tai42_toolbox-0.1.0/LICENSE +202 -0
  2. tai42_toolbox-0.1.0/MANIFEST.in +1 -0
  3. tai42_toolbox-0.1.0/NOTICE +5 -0
  4. tai42_toolbox-0.1.0/PKG-INFO +217 -0
  5. tai42_toolbox-0.1.0/README.md +171 -0
  6. tai42_toolbox-0.1.0/pyproject.toml +127 -0
  7. tai42_toolbox-0.1.0/setup.cfg +4 -0
  8. tai42_toolbox-0.1.0/src/tai42_toolbox/__init__.py +10 -0
  9. tai42_toolbox-0.1.0/src/tai42_toolbox/_internal/__init__.py +7 -0
  10. tai42_toolbox-0.1.0/src/tai42_toolbox/_internal/extensions/__init__.py +7 -0
  11. tai42_toolbox-0.1.0/src/tai42_toolbox/_internal/extensions/batch_executor.py +94 -0
  12. tai42_toolbox-0.1.0/src/tai42_toolbox/_internal/extensions/cache_store.py +123 -0
  13. tai42_toolbox-0.1.0/src/tai42_toolbox/_internal/extensions/chain_executor.py +34 -0
  14. tai42_toolbox-0.1.0/src/tai42_toolbox/_internal/extensions/output_schema_validator.py +38 -0
  15. tai42_toolbox-0.1.0/src/tai42_toolbox/_internal/extensions/prometheus_counters.py +76 -0
  16. tai42_toolbox-0.1.0/src/tai42_toolbox/_internal/extensions/proxy_context.py +151 -0
  17. tai42_toolbox-0.1.0/src/tai42_toolbox/_internal/extensions/signature.py +24 -0
  18. tai42_toolbox-0.1.0/src/tai42_toolbox/_internal/extensions/socket_routing.py +302 -0
  19. tai42_toolbox-0.1.0/src/tai42_toolbox/_internal/tools/__init__.py +8 -0
  20. tai42_toolbox-0.1.0/src/tai42_toolbox/_internal/tools/http_client.py +349 -0
  21. tai42_toolbox-0.1.0/src/tai42_toolbox/extensions/__init__.py +6 -0
  22. tai42_toolbox-0.1.0/src/tai42_toolbox/extensions/batch.py +101 -0
  23. tai42_toolbox-0.1.0/src/tai42_toolbox/extensions/cache.py +86 -0
  24. tai42_toolbox-0.1.0/src/tai42_toolbox/extensions/chain.py +67 -0
  25. tai42_toolbox-0.1.0/src/tai42_toolbox/extensions/output_schema.py +90 -0
  26. tai42_toolbox-0.1.0/src/tai42_toolbox/extensions/prometheus.py +58 -0
  27. tai42_toolbox-0.1.0/src/tai42_toolbox/extensions/proxy.py +81 -0
  28. tai42_toolbox-0.1.0/src/tai42_toolbox/py.typed +0 -0
  29. tai42_toolbox-0.1.0/src/tai42_toolbox/tai-plugin.yml +72 -0
  30. tai42_toolbox-0.1.0/src/tai42_toolbox/tools/__init__.py +4 -0
  31. tai42_toolbox-0.1.0/src/tai42_toolbox/tools/current_time_info.py +61 -0
  32. tai42_toolbox-0.1.0/src/tai42_toolbox/tools/generate_embeddings.py +57 -0
  33. tai42_toolbox-0.1.0/src/tai42_toolbox/tools/generate_uuid.py +17 -0
  34. tai42_toolbox-0.1.0/src/tai42_toolbox/tools/pad_embeddings.py +46 -0
  35. tai42_toolbox-0.1.0/src/tai42_toolbox/tools/request.py +57 -0
  36. tai42_toolbox-0.1.0/src/tai42_toolbox.egg-info/PKG-INFO +217 -0
  37. tai42_toolbox-0.1.0/src/tai42_toolbox.egg-info/SOURCES.txt +38 -0
  38. tai42_toolbox-0.1.0/src/tai42_toolbox.egg-info/dependency_links.txt +1 -0
  39. tai42_toolbox-0.1.0/src/tai42_toolbox.egg-info/requires.txt +29 -0
  40. tai42_toolbox-0.1.0/src/tai42_toolbox.egg-info/top_level.txt +1 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1 @@
1
+ prune tests
@@ -0,0 +1,5 @@
1
+ tai42-toolbox
2
+ Copyright 2026 tai42
3
+
4
+ This product includes software developed at tai42 (https://tai42.ai).
5
+ Licensed under the Apache License, Version 2.0.
@@ -0,0 +1,217 @@
1
+ Metadata-Version: 2.4
2
+ Name: tai42-toolbox
3
+ Version: 0.1.0
4
+ Summary: Reference contrib package for the TAI ecosystem: opt-in, manifest-loaded generic tools and tool extensions (a tool extension extends a single tool).
5
+ Author-email: tai42 <oss@tai42.ai>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://tai42.ai
8
+ Project-URL: Repository, https://github.com/tai42ai/tai-toolbox
9
+ Project-URL: Issues, https://github.com/tai42ai/tai-toolbox/issues
10
+ Project-URL: Changelog, https://github.com/tai42ai/tai-toolbox/blob/main/CHANGELOG.md
11
+ Keywords: tai,tools,tool-extensions,cache,proxy,batch,chain,http,embeddings
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Typing :: Typed
18
+ Requires-Python: >=3.13
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ License-File: NOTICE
22
+ Requires-Dist: tai42-contract<0.2,>=0.1
23
+ Requires-Dist: tai42-kit<0.2,>=0.1
24
+ Requires-Dist: makefun>=1.15
25
+ Requires-Dist: pydantic>=2.12
26
+ Requires-Dist: pydantic-settings>=2.11
27
+ Provides-Extra: http
28
+ Requires-Dist: tai42-kit[curl]; extra == "http"
29
+ Provides-Extra: prometheus
30
+ Requires-Dist: prometheus-client>=0.24; extra == "prometheus"
31
+ Provides-Extra: chain
32
+ Requires-Dist: tai42-kit[jq]; extra == "chain"
33
+ Provides-Extra: embeddings
34
+ Requires-Dist: tai42-kit[llm]; extra == "embeddings"
35
+ Provides-Extra: proxy
36
+ Requires-Dist: PySocks~=1.7.1; extra == "proxy"
37
+ Provides-Extra: dev
38
+ Requires-Dist: tai42-toolbox[chain,embeddings,http,prometheus,proxy]; extra == "dev"
39
+ Requires-Dist: pytest>=8; extra == "dev"
40
+ Requires-Dist: pytest-cov>=5; extra == "dev"
41
+ Requires-Dist: ruff>=0.6; extra == "dev"
42
+ Requires-Dist: pyright>=1.1.389; extra == "dev"
43
+ Requires-Dist: trustme>=1.1; extra == "dev"
44
+ Requires-Dist: pyyaml>=6; extra == "dev"
45
+ Dynamic: license-file
46
+
47
+ # tai42-toolbox
48
+
49
+ [![CI](https://github.com/tai42ai/tai-toolbox/actions/workflows/ci.yml/badge.svg)](https://github.com/tai42ai/tai-toolbox/actions/workflows/ci.yml)
50
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE)
51
+
52
+ The reference contrib package for the TAI ecosystem — an opt-in, manifest-loaded
53
+ collection of generic **tools** and **tool extensions**.
54
+
55
+ > A plugin extends the platform; a *tool extension* extends a single tool.
56
+
57
+ Everything here registers through the `tai42_app` handle from `tai42_contract.app`
58
+ and is loaded by the host from the manifest (`tools[].module` /
59
+ `extensions_modules`). Its only tai-* dependencies are `tai42-contract` (the
60
+ interfaces it registers through) and `tai42-kit` (the curl client, the jq
61
+ compiler, and the llm/embedding factories the heavier modules wire to). It
62
+ **never** imports the skeleton — the toolbox is contract-facing.
63
+
64
+ ## Install
65
+
66
+ Requires **Python 3.13+**. Nothing is on PyPI yet, so install from source — clone
67
+ this repo and add it as an editable dependency of the environment that runs the
68
+ server (or let it ride in through `tai42-skeleton`'s `[toolbox]` extra):
69
+
70
+ ```bash
71
+ git clone https://github.com/tai42ai/tai-toolbox
72
+ cd tai-skeleton # or your own app checkout
73
+ uv add --editable ../tai-toolbox # once published: uv add tai42-toolbox
74
+ uv add --editable "../tai-toolbox[http]" # add only the extras you use
75
+ ```
76
+
77
+ The base install stays light. Each heavier module is gated behind its own extra;
78
+ a module whose extra is missing fails loudly at import with an
79
+ `install tai42-toolbox[extra]` hint — never a silent skip.
80
+
81
+ | Extra | Pulls | Backs |
82
+ |---|---|---|
83
+ | `http` | `tai42-kit[curl]` | the `request` tool |
84
+ | `prometheus` | `prometheus-client` | the `prometheus_metrics` tool extension |
85
+ | `chain` | `tai42-kit[jq]` | the `chain` tool extension |
86
+ | `embeddings` | `tai42-kit[llm]` | the `generate_embeddings` and `pad_embeddings` tools |
87
+ | `proxy` | `PySocks` | SOCKS routing in the `proxy` tool extension (its HTTP/HTTPS path is stdlib-only) |
88
+
89
+ ## Catalog
90
+
91
+ One row per registered artifact. **Kind** is the `ExtensionKind` for a tool
92
+ extension (Wrapper / Transformer) or `Tool` for a tool. **Extra** is the gating
93
+ optional dependency, or `—` when the module needs none. A gated module whose
94
+ extra is not installed fails loudly at import with an `install tai42-toolbox[extra]`
95
+ hint — never a silent skip.
96
+
97
+ ### Tool extensions
98
+
99
+ | Name | Kind | Extra | Description |
100
+ |---|---|---|---|
101
+ | `cache` | Wrapper | `—` | Memoizes the tool's results by call arguments and single-flights concurrent identical calls; adds an `exp` (seconds-to-live) control kwarg. |
102
+ | `proxy` | Wrapper | `proxy` | Routes the tool's connections through a SOCKS or HTTP/HTTPS proxy; adds a `proxies` pool control kwarg. The `proxy` extra (PySocks) is needed only for SOCKS; the HTTP/HTTPS path is stdlib-only. |
103
+ | `prometheus_metrics` | Wrapper | `prometheus` | Records a call count, an error count, and a run-time histogram per invocation; presents the tool's input schema unchanged. |
104
+ | `batch` | Transformer | `—` | Runs many instances of the tool from a list of parameter sets, sequentially or in parallel, returning results in input order. |
105
+ | `chain` | Transformer | `chain` | Calls the tool, transforms its output with a jq expression, then calls a second named tool with the result. |
106
+ | `output_schema` | Transformer | `—` | Forces the tool's advertised output schema to a JSON Schema supplied in the combo's `config` (under a `schema` key) and validates each result against it, raising loudly on a mismatch. |
107
+
108
+ ### Tools
109
+
110
+ | Name | Kind | Extra | Description |
111
+ |---|---|---|---|
112
+ | `generate_embeddings` | Tool | `embeddings` | Generates embedding vectors for a string or list of strings via the configured provider. |
113
+ | `pad_embeddings` | Tool | `embeddings` | Pads embedding vectors with zeros up to a fixed width; raises rather than truncating a vector already wider than the target. |
114
+ | `request` | Tool | `http` | Executes an HTTP request through tai42-kit's pooled curl client, with optional keyed session reuse (shared cookies and connections). |
115
+ | `generate_uuid` | Tool | `—` | Generates a random version-4 UUID. |
116
+ | `current_time_info` | Tool | `—` | Returns the current time as a structured object (UTC, local, and high-precision system timestamps). |
117
+
118
+ ## Security
119
+
120
+ **SSRF guard (`request` tool).** The `request` tool fetches a caller-supplied URL
121
+ server-side, so an agent steered by a poisoned page could aim it at internal-only
122
+ services or the cloud metadata endpoint. A guard is **on by default**: it resolves
123
+ each target host and refuses any address that is private, loopback, link-local,
124
+ reserved, multicast, or unspecified, and refuses a response larger than a cap
125
+ (loudly, never truncated). The guard itself lives in tai42-kit
126
+ (`tai42_kit.net.url_guard`) and is shared with kit's `fetch_url` download; configure
127
+ it with `TAI_URL_GUARD_`-prefixed settings:
128
+
129
+ | Setting | Default | Meaning |
130
+ |---|---|---|
131
+ | `TAI_URL_GUARD_ENABLED` | `true` | Turn the guard off entirely. |
132
+ | `TAI_URL_GUARD_ALLOW_CIDRS` | `[]` | CIDR ranges to opt back in (e.g. `["10.0.0.0/8"]`) for a deployment that deliberately reaches internal hosts. |
133
+ | `TAI_URL_GUARD_MAX_RESPONSE_BYTES` | `104857600` | Refuse a response body larger than this. |
134
+ | `TAI_URL_GUARD_MAX_REDIRECTS` | `20` | Redirect-follow limit for a guarded download (kit's `fetch_url`). |
135
+
136
+ **DNS-rebinding.** Resolving a host and then letting the HTTP client re-resolve
137
+ it at connect time leaves a rebinding window (an attacker answers a public
138
+ address during the check and an internal one at connect). The `request` tool
139
+ closes this by resolving each host once, validating every returned address, and
140
+ pinning curl to that validated address per request via `CURLOPT_RESOLVE`
141
+ (resolve-once, connect-to-validated-IP). TLS is unaffected — SNI and certificate
142
+ validation still use the original hostname. As defense in depth, network egress
143
+ controls remain worthwhile but are not required to close rebinding here.
144
+
145
+ **Response size cap.** The `request` tool streams the response body and enforces
146
+ the size cap chunk by chunk, refusing an over-cap body the moment it crosses the
147
+ limit — never after buffering the whole body.
148
+
149
+ While the guard is on, the `request` tool does not auto-follow redirects (its curl
150
+ transport has no per-hop hook to re-check each redirect target), so a 3xx is
151
+ returned as-is.
152
+
153
+ **`proxy` routing (task-scoped).** The `proxy` tool extension routes a wrapped
154
+ tool's connections through a chosen proxy. Routing is dispatched on a contextvar,
155
+ so it is **task-scoped**: only the routed call's own connections go through the
156
+ proxy, and concurrent routed and unrouted calls run in parallel without affecting
157
+ each other. The HTTP/HTTPS proxy verifies the proxy's own TLS certificate and
158
+ sends the destination host to the proxy to resolve (no local DNS leak). A proxy
159
+ that accepts TCP but never answers the handshake cannot wedge the call: the
160
+ connect/negotiation runs under `PROXY_CONNECT_TIMEOUT`.
161
+
162
+ Configure the proxy pool and policy with `PROXY_`-prefixed settings:
163
+
164
+ | Setting | Default | Meaning |
165
+ |---|---|---|
166
+ | `PROXY_POOL` | `[]` | The operator proxy-URL pool routed over when a call passes no `proxies` (or a call selects from). |
167
+ | `PROXY_ALLOW_CALLER_URLS` | `false` | When false, a call's `proxies` kwarg may only select URLs already in `PROXY_POOL`; an out-of-pool URL is refused loudly. Set true to let a call supply its own proxy URL. |
168
+ | `PROXY_CONNECT_TIMEOUT` | `30` | Connect/negotiation timeout (seconds) for the proxy handshake. |
169
+
170
+ With `PROXY_ALLOW_CALLER_URLS=true`, the routed call's own traffic — its SNI and
171
+ any non-TLS content — is visible to the caller-chosen proxy; enable it only when a
172
+ caller supplying its own proxy is intended.
173
+
174
+ **Proxy host SSRF guard (caller-supplied only).** A caller-supplied proxy host (a
175
+ selected URL not in `PROXY_POOL`, and each proxy in the `request` tool's own
176
+ `session_params.proxies`/`proxy`) is run through the SSRF guard when the guard is
177
+ on: its host is resolved and validated, and the connection targets the validated
178
+ address rather than re-resolving the hostname, closing DNS-rebinding on the proxy
179
+ hop. For an HTTPS proxy the TLS SNI and certificate verification still use the
180
+ original hostname. A rejected proxy host raises loudly; nothing is routed. The
181
+ `PROXY_POOL` entries are **trusted-by-configuration** (an operator-vetted pool,
182
+ often a private-IP corporate egress proxy) and are not guarded — guarding them
183
+ would break a standard deploy and force an over-broad `TAI_URL_GUARD_ALLOW_CIDRS`.
184
+
185
+ **Routing propagation boundary.** The route follows the asyncio task tree: child
186
+ tasks and `asyncio.to_thread` inherit it, but `loop.run_in_executor` and a raw
187
+ `threading.Thread` do not — a tool offloading network work that way silently
188
+ escapes routing. The dispatcher is Python-level and cannot see sockets opened by a
189
+ C-level network stack (a libcurl-class client); for the `request` tool, use its
190
+ native `proxies` session param rather than this extension. The route is captured
191
+ when a socket is created, so a tool that reuses a keep-alive connection from a pool
192
+ built outside the routed window is not re-routed. A tool that needs routing to bind
193
+ reliably must open its connections inside the routed window (e.g. a per-call
194
+ session), not reuse a shared pool built outside it.
195
+
196
+ The route is also **process-local**: the extension registers with
197
+ `requires_body_locality=True` because its wrapper routes only when it executes in
198
+ the process running the tool body. In a stacked combo the `proxy` extension must
199
+ bind inside any execution-relocating extension (a BACKEND-kind extension, which
200
+ ships the tool body to a worker process), so the routing wrapper travels with the
201
+ body; the platform reads the marker and rejects the wrong order at bind time.
202
+
203
+ ## Development
204
+
205
+ ```bash
206
+ uv sync --all-extras
207
+ uv run ruff check
208
+ uv run pyright
209
+ uv run pytest
210
+ ```
211
+
212
+ `[tool.uv.sources]` resolves `tai42-contract` and `tai42-kit` from sibling checkouts
213
+ for local development; the published wheel floors them from the index.
214
+
215
+ ## License
216
+
217
+ Apache-2.0. See `LICENSE` and `NOTICE`.
@@ -0,0 +1,171 @@
1
+ # tai42-toolbox
2
+
3
+ [![CI](https://github.com/tai42ai/tai-toolbox/actions/workflows/ci.yml/badge.svg)](https://github.com/tai42ai/tai-toolbox/actions/workflows/ci.yml)
4
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](LICENSE)
5
+
6
+ The reference contrib package for the TAI ecosystem — an opt-in, manifest-loaded
7
+ collection of generic **tools** and **tool extensions**.
8
+
9
+ > A plugin extends the platform; a *tool extension* extends a single tool.
10
+
11
+ Everything here registers through the `tai42_app` handle from `tai42_contract.app`
12
+ and is loaded by the host from the manifest (`tools[].module` /
13
+ `extensions_modules`). Its only tai-* dependencies are `tai42-contract` (the
14
+ interfaces it registers through) and `tai42-kit` (the curl client, the jq
15
+ compiler, and the llm/embedding factories the heavier modules wire to). It
16
+ **never** imports the skeleton — the toolbox is contract-facing.
17
+
18
+ ## Install
19
+
20
+ Requires **Python 3.13+**. Nothing is on PyPI yet, so install from source — clone
21
+ this repo and add it as an editable dependency of the environment that runs the
22
+ server (or let it ride in through `tai42-skeleton`'s `[toolbox]` extra):
23
+
24
+ ```bash
25
+ git clone https://github.com/tai42ai/tai-toolbox
26
+ cd tai-skeleton # or your own app checkout
27
+ uv add --editable ../tai-toolbox # once published: uv add tai42-toolbox
28
+ uv add --editable "../tai-toolbox[http]" # add only the extras you use
29
+ ```
30
+
31
+ The base install stays light. Each heavier module is gated behind its own extra;
32
+ a module whose extra is missing fails loudly at import with an
33
+ `install tai42-toolbox[extra]` hint — never a silent skip.
34
+
35
+ | Extra | Pulls | Backs |
36
+ |---|---|---|
37
+ | `http` | `tai42-kit[curl]` | the `request` tool |
38
+ | `prometheus` | `prometheus-client` | the `prometheus_metrics` tool extension |
39
+ | `chain` | `tai42-kit[jq]` | the `chain` tool extension |
40
+ | `embeddings` | `tai42-kit[llm]` | the `generate_embeddings` and `pad_embeddings` tools |
41
+ | `proxy` | `PySocks` | SOCKS routing in the `proxy` tool extension (its HTTP/HTTPS path is stdlib-only) |
42
+
43
+ ## Catalog
44
+
45
+ One row per registered artifact. **Kind** is the `ExtensionKind` for a tool
46
+ extension (Wrapper / Transformer) or `Tool` for a tool. **Extra** is the gating
47
+ optional dependency, or `—` when the module needs none. A gated module whose
48
+ extra is not installed fails loudly at import with an `install tai42-toolbox[extra]`
49
+ hint — never a silent skip.
50
+
51
+ ### Tool extensions
52
+
53
+ | Name | Kind | Extra | Description |
54
+ |---|---|---|---|
55
+ | `cache` | Wrapper | `—` | Memoizes the tool's results by call arguments and single-flights concurrent identical calls; adds an `exp` (seconds-to-live) control kwarg. |
56
+ | `proxy` | Wrapper | `proxy` | Routes the tool's connections through a SOCKS or HTTP/HTTPS proxy; adds a `proxies` pool control kwarg. The `proxy` extra (PySocks) is needed only for SOCKS; the HTTP/HTTPS path is stdlib-only. |
57
+ | `prometheus_metrics` | Wrapper | `prometheus` | Records a call count, an error count, and a run-time histogram per invocation; presents the tool's input schema unchanged. |
58
+ | `batch` | Transformer | `—` | Runs many instances of the tool from a list of parameter sets, sequentially or in parallel, returning results in input order. |
59
+ | `chain` | Transformer | `chain` | Calls the tool, transforms its output with a jq expression, then calls a second named tool with the result. |
60
+ | `output_schema` | Transformer | `—` | Forces the tool's advertised output schema to a JSON Schema supplied in the combo's `config` (under a `schema` key) and validates each result against it, raising loudly on a mismatch. |
61
+
62
+ ### Tools
63
+
64
+ | Name | Kind | Extra | Description |
65
+ |---|---|---|---|
66
+ | `generate_embeddings` | Tool | `embeddings` | Generates embedding vectors for a string or list of strings via the configured provider. |
67
+ | `pad_embeddings` | Tool | `embeddings` | Pads embedding vectors with zeros up to a fixed width; raises rather than truncating a vector already wider than the target. |
68
+ | `request` | Tool | `http` | Executes an HTTP request through tai42-kit's pooled curl client, with optional keyed session reuse (shared cookies and connections). |
69
+ | `generate_uuid` | Tool | `—` | Generates a random version-4 UUID. |
70
+ | `current_time_info` | Tool | `—` | Returns the current time as a structured object (UTC, local, and high-precision system timestamps). |
71
+
72
+ ## Security
73
+
74
+ **SSRF guard (`request` tool).** The `request` tool fetches a caller-supplied URL
75
+ server-side, so an agent steered by a poisoned page could aim it at internal-only
76
+ services or the cloud metadata endpoint. A guard is **on by default**: it resolves
77
+ each target host and refuses any address that is private, loopback, link-local,
78
+ reserved, multicast, or unspecified, and refuses a response larger than a cap
79
+ (loudly, never truncated). The guard itself lives in tai42-kit
80
+ (`tai42_kit.net.url_guard`) and is shared with kit's `fetch_url` download; configure
81
+ it with `TAI_URL_GUARD_`-prefixed settings:
82
+
83
+ | Setting | Default | Meaning |
84
+ |---|---|---|
85
+ | `TAI_URL_GUARD_ENABLED` | `true` | Turn the guard off entirely. |
86
+ | `TAI_URL_GUARD_ALLOW_CIDRS` | `[]` | CIDR ranges to opt back in (e.g. `["10.0.0.0/8"]`) for a deployment that deliberately reaches internal hosts. |
87
+ | `TAI_URL_GUARD_MAX_RESPONSE_BYTES` | `104857600` | Refuse a response body larger than this. |
88
+ | `TAI_URL_GUARD_MAX_REDIRECTS` | `20` | Redirect-follow limit for a guarded download (kit's `fetch_url`). |
89
+
90
+ **DNS-rebinding.** Resolving a host and then letting the HTTP client re-resolve
91
+ it at connect time leaves a rebinding window (an attacker answers a public
92
+ address during the check and an internal one at connect). The `request` tool
93
+ closes this by resolving each host once, validating every returned address, and
94
+ pinning curl to that validated address per request via `CURLOPT_RESOLVE`
95
+ (resolve-once, connect-to-validated-IP). TLS is unaffected — SNI and certificate
96
+ validation still use the original hostname. As defense in depth, network egress
97
+ controls remain worthwhile but are not required to close rebinding here.
98
+
99
+ **Response size cap.** The `request` tool streams the response body and enforces
100
+ the size cap chunk by chunk, refusing an over-cap body the moment it crosses the
101
+ limit — never after buffering the whole body.
102
+
103
+ While the guard is on, the `request` tool does not auto-follow redirects (its curl
104
+ transport has no per-hop hook to re-check each redirect target), so a 3xx is
105
+ returned as-is.
106
+
107
+ **`proxy` routing (task-scoped).** The `proxy` tool extension routes a wrapped
108
+ tool's connections through a chosen proxy. Routing is dispatched on a contextvar,
109
+ so it is **task-scoped**: only the routed call's own connections go through the
110
+ proxy, and concurrent routed and unrouted calls run in parallel without affecting
111
+ each other. The HTTP/HTTPS proxy verifies the proxy's own TLS certificate and
112
+ sends the destination host to the proxy to resolve (no local DNS leak). A proxy
113
+ that accepts TCP but never answers the handshake cannot wedge the call: the
114
+ connect/negotiation runs under `PROXY_CONNECT_TIMEOUT`.
115
+
116
+ Configure the proxy pool and policy with `PROXY_`-prefixed settings:
117
+
118
+ | Setting | Default | Meaning |
119
+ |---|---|---|
120
+ | `PROXY_POOL` | `[]` | The operator proxy-URL pool routed over when a call passes no `proxies` (or a call selects from). |
121
+ | `PROXY_ALLOW_CALLER_URLS` | `false` | When false, a call's `proxies` kwarg may only select URLs already in `PROXY_POOL`; an out-of-pool URL is refused loudly. Set true to let a call supply its own proxy URL. |
122
+ | `PROXY_CONNECT_TIMEOUT` | `30` | Connect/negotiation timeout (seconds) for the proxy handshake. |
123
+
124
+ With `PROXY_ALLOW_CALLER_URLS=true`, the routed call's own traffic — its SNI and
125
+ any non-TLS content — is visible to the caller-chosen proxy; enable it only when a
126
+ caller supplying its own proxy is intended.
127
+
128
+ **Proxy host SSRF guard (caller-supplied only).** A caller-supplied proxy host (a
129
+ selected URL not in `PROXY_POOL`, and each proxy in the `request` tool's own
130
+ `session_params.proxies`/`proxy`) is run through the SSRF guard when the guard is
131
+ on: its host is resolved and validated, and the connection targets the validated
132
+ address rather than re-resolving the hostname, closing DNS-rebinding on the proxy
133
+ hop. For an HTTPS proxy the TLS SNI and certificate verification still use the
134
+ original hostname. A rejected proxy host raises loudly; nothing is routed. The
135
+ `PROXY_POOL` entries are **trusted-by-configuration** (an operator-vetted pool,
136
+ often a private-IP corporate egress proxy) and are not guarded — guarding them
137
+ would break a standard deploy and force an over-broad `TAI_URL_GUARD_ALLOW_CIDRS`.
138
+
139
+ **Routing propagation boundary.** The route follows the asyncio task tree: child
140
+ tasks and `asyncio.to_thread` inherit it, but `loop.run_in_executor` and a raw
141
+ `threading.Thread` do not — a tool offloading network work that way silently
142
+ escapes routing. The dispatcher is Python-level and cannot see sockets opened by a
143
+ C-level network stack (a libcurl-class client); for the `request` tool, use its
144
+ native `proxies` session param rather than this extension. The route is captured
145
+ when a socket is created, so a tool that reuses a keep-alive connection from a pool
146
+ built outside the routed window is not re-routed. A tool that needs routing to bind
147
+ reliably must open its connections inside the routed window (e.g. a per-call
148
+ session), not reuse a shared pool built outside it.
149
+
150
+ The route is also **process-local**: the extension registers with
151
+ `requires_body_locality=True` because its wrapper routes only when it executes in
152
+ the process running the tool body. In a stacked combo the `proxy` extension must
153
+ bind inside any execution-relocating extension (a BACKEND-kind extension, which
154
+ ships the tool body to a worker process), so the routing wrapper travels with the
155
+ body; the platform reads the marker and rejects the wrong order at bind time.
156
+
157
+ ## Development
158
+
159
+ ```bash
160
+ uv sync --all-extras
161
+ uv run ruff check
162
+ uv run pyright
163
+ uv run pytest
164
+ ```
165
+
166
+ `[tool.uv.sources]` resolves `tai42-contract` and `tai42-kit` from sibling checkouts
167
+ for local development; the published wheel floors them from the index.
168
+
169
+ ## License
170
+
171
+ Apache-2.0. See `LICENSE` and `NOTICE`.