squid-providers 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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Aaron Slater
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,12 @@
1
+ # Public source distributions contain runtime code and the two public documents.
2
+ include README.md LICENSE
3
+ include docs/ARCHITECTURE.md
4
+ exclude AGENTS.md requirements-dev.txt .gitignore
5
+ exclude docs/dev-log.md
6
+ prune tests
7
+ prune build
8
+ prune dist
9
+ prune .venv
10
+ prune .pytest_cache
11
+ prune .code-squid
12
+ global-exclude __pycache__ *.py[cod] .env .env.*
@@ -0,0 +1,142 @@
1
+ Metadata-Version: 2.4
2
+ Name: squid-providers
3
+ Version: 0.1.0
4
+ Summary: First-party model transports, configuration, and discovery for Squid Core
5
+ Author: Aaron Slater
6
+ License-Expression: MIT
7
+ Requires-Python: >=3.11
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: squid-core==0.1.0
11
+ Requires-Dist: openai
12
+ Requires-Dist: httpx
13
+ Dynamic: license-file
14
+
15
+ # Squid Providers
16
+
17
+ Squid Providers contains the model integrations used by Squid Core and Code Squid.
18
+
19
+ It handles connections to model servers and APIs, model discovery, streaming,
20
+ tool calls, token usage, and converting provider responses into the format
21
+ Squid Core expects.
22
+
23
+ ## Supported providers
24
+
25
+ | Provider | Default endpoint |
26
+ | --- | --- |
27
+ | Ollama | `http://127.0.0.1:11434` |
28
+ | LM Studio | `http://127.0.0.1:1234/v1` |
29
+ | OpenRouter | `https://openrouter.ai/api/v1` |
30
+ | OpenAI-compatible servers | `http://127.0.0.1:8000/v1` |
31
+
32
+ The provider IDs used in configuration are `ollama`, `lm_studio`, `openrouter`,
33
+ and `openai_compatible`.
34
+
35
+ Support for tools, images, reasoning, and other model features depends on the
36
+ provider and model.
37
+
38
+ OpenRouter requires an API key for inference. Local providers do not require one
39
+ unless the server itself is configured to use authentication.
40
+
41
+ ## Installation
42
+
43
+ Squid Providers requires Python 3.11 or newer and depends on Squid Core.
44
+
45
+ Install from PyPI:
46
+
47
+ ```bash
48
+ pip install squid-providers
49
+ ```
50
+
51
+ Squid Core and the required dependencies are installed automatically.
52
+
53
+ The model server or API you want to use must be set up separately.
54
+
55
+ ## Usage
56
+
57
+ This example connects to Ollama and sends a simple request using a model that is
58
+ already installed:
59
+
60
+ ```python
61
+ from squid_providers.catalog import build_provider, resolve_config
62
+ from squid_providers.settings import ProviderSettings
63
+
64
+
65
+ config = resolve_config("ollama", {})
66
+
67
+ settings = ProviderSettings(
68
+ provider="ollama",
69
+ model_name="YOUR_MODEL_ID",
70
+ base_url=config["base_url"],
71
+ api_key=config["api_key"],
72
+ config=config,
73
+ )
74
+
75
+ provider = build_provider(settings)
76
+
77
+ response = provider.create_response(
78
+ model=settings.model_name,
79
+ messages=[{"role": "user", "content": "Say hello in one sentence."}],
80
+ tools=[],
81
+ )
82
+
83
+ print(response.content)
84
+ ```
85
+
86
+ `build_provider()` creates the provider connection. Calling
87
+ `create_response()` sends the request to the model.
88
+
89
+ Providers follow Squid Core's provider contract and can be passed directly into
90
+ Squid Core.
91
+
92
+ ## Configuration and model discovery
93
+
94
+ `resolve_config(provider_id, overrides)` combines provider defaults with any
95
+ connection settings you supply.
96
+
97
+ Connection settings can include:
98
+
99
+ - `base_url`
100
+ - `api_key`
101
+ - `api_key_env`
102
+
103
+ Ollama also supports `request_timeout`.
104
+
105
+ OpenRouter uses `OPENROUTER_API_KEY` by default.
106
+
107
+ Squid Providers also includes helpers for checking providers and discovering
108
+ available models:
109
+
110
+ - `provider_catalog()` returns provider information.
111
+ - `configuration_status()` checks whether a provider is configured.
112
+ - `provider_ready(settings)` checks whether the configured service is available.
113
+ - `discover_models(settings)` returns available model IDs.
114
+ - `discover_model_records(settings)` returns additional model information when
115
+ the provider makes it available.
116
+
117
+ Applications are responsible for choosing models and storing their own settings.
118
+
119
+ ## Building with Squid Providers
120
+
121
+ Squid Providers is separate from Squid Core so model integrations do not have to
122
+ be built into the agent itself.
123
+
124
+ Squid Core handles the agent loop and tool execution. Squid Providers handles
125
+ the connections to the models.
126
+
127
+ For a deeper look at the package and its public interfaces, see
128
+ [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md).
129
+
130
+ ## Testing
131
+
132
+ Run the test suite with:
133
+
134
+ ```powershell
135
+ python -m pytest tests
136
+ ```
137
+
138
+ The tests use mocked providers and do not require live model inference.
139
+
140
+ ## License
141
+
142
+ Squid Providers is licensed under the [MIT License](LICENSE).
@@ -0,0 +1,128 @@
1
+ # Squid Providers
2
+
3
+ Squid Providers contains the model integrations used by Squid Core and Code Squid.
4
+
5
+ It handles connections to model servers and APIs, model discovery, streaming,
6
+ tool calls, token usage, and converting provider responses into the format
7
+ Squid Core expects.
8
+
9
+ ## Supported providers
10
+
11
+ | Provider | Default endpoint |
12
+ | --- | --- |
13
+ | Ollama | `http://127.0.0.1:11434` |
14
+ | LM Studio | `http://127.0.0.1:1234/v1` |
15
+ | OpenRouter | `https://openrouter.ai/api/v1` |
16
+ | OpenAI-compatible servers | `http://127.0.0.1:8000/v1` |
17
+
18
+ The provider IDs used in configuration are `ollama`, `lm_studio`, `openrouter`,
19
+ and `openai_compatible`.
20
+
21
+ Support for tools, images, reasoning, and other model features depends on the
22
+ provider and model.
23
+
24
+ OpenRouter requires an API key for inference. Local providers do not require one
25
+ unless the server itself is configured to use authentication.
26
+
27
+ ## Installation
28
+
29
+ Squid Providers requires Python 3.11 or newer and depends on Squid Core.
30
+
31
+ Install from PyPI:
32
+
33
+ ```bash
34
+ pip install squid-providers
35
+ ```
36
+
37
+ Squid Core and the required dependencies are installed automatically.
38
+
39
+ The model server or API you want to use must be set up separately.
40
+
41
+ ## Usage
42
+
43
+ This example connects to Ollama and sends a simple request using a model that is
44
+ already installed:
45
+
46
+ ```python
47
+ from squid_providers.catalog import build_provider, resolve_config
48
+ from squid_providers.settings import ProviderSettings
49
+
50
+
51
+ config = resolve_config("ollama", {})
52
+
53
+ settings = ProviderSettings(
54
+ provider="ollama",
55
+ model_name="YOUR_MODEL_ID",
56
+ base_url=config["base_url"],
57
+ api_key=config["api_key"],
58
+ config=config,
59
+ )
60
+
61
+ provider = build_provider(settings)
62
+
63
+ response = provider.create_response(
64
+ model=settings.model_name,
65
+ messages=[{"role": "user", "content": "Say hello in one sentence."}],
66
+ tools=[],
67
+ )
68
+
69
+ print(response.content)
70
+ ```
71
+
72
+ `build_provider()` creates the provider connection. Calling
73
+ `create_response()` sends the request to the model.
74
+
75
+ Providers follow Squid Core's provider contract and can be passed directly into
76
+ Squid Core.
77
+
78
+ ## Configuration and model discovery
79
+
80
+ `resolve_config(provider_id, overrides)` combines provider defaults with any
81
+ connection settings you supply.
82
+
83
+ Connection settings can include:
84
+
85
+ - `base_url`
86
+ - `api_key`
87
+ - `api_key_env`
88
+
89
+ Ollama also supports `request_timeout`.
90
+
91
+ OpenRouter uses `OPENROUTER_API_KEY` by default.
92
+
93
+ Squid Providers also includes helpers for checking providers and discovering
94
+ available models:
95
+
96
+ - `provider_catalog()` returns provider information.
97
+ - `configuration_status()` checks whether a provider is configured.
98
+ - `provider_ready(settings)` checks whether the configured service is available.
99
+ - `discover_models(settings)` returns available model IDs.
100
+ - `discover_model_records(settings)` returns additional model information when
101
+ the provider makes it available.
102
+
103
+ Applications are responsible for choosing models and storing their own settings.
104
+
105
+ ## Building with Squid Providers
106
+
107
+ Squid Providers is separate from Squid Core so model integrations do not have to
108
+ be built into the agent itself.
109
+
110
+ Squid Core handles the agent loop and tool execution. Squid Providers handles
111
+ the connections to the models.
112
+
113
+ For a deeper look at the package and its public interfaces, see
114
+ [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md).
115
+
116
+ ## Testing
117
+
118
+ Run the test suite with:
119
+
120
+ ```powershell
121
+ python -m pytest tests
122
+ ```
123
+
124
+ The tests use mocked providers and do not require live model inference.
125
+
126
+ ## License
127
+
128
+ Squid Providers is licensed under the [MIT License](LICENSE).
@@ -0,0 +1,125 @@
1
+ # Squid Providers Architecture
2
+
3
+ Providers owns transports and an explicit first-party catalog. It imports only
4
+ squid_core.model_response and squid_core.providers.base, never Code Squid.
5
+ Transports return ModelResponse for streaming and non-streaming calls.
6
+ CancellationMonitor and raw tracing remain provider-owned; StreamCancelled
7
+ retains Core's single exception identity.
8
+
9
+ Application API in squid_providers.catalog: PROVIDER_PROFILES, PROFILES_BY_ID,
10
+ VALID_PROVIDERS, friendly_provider_name, resolve_provider_name,
11
+ validate_config, resolve_config, build_provider, provider_ready, discover_models, discover_model_records, ModelRecord,
12
+ and tool_call_content_mode. ProviderSettings and shared validators live in
13
+ squid_providers.settings. The catalog owns identities/defaults, credential
14
+ variable names, supported scoped config, constructors,
15
+ readiness/discovery and replay policy. request_timeout is supported by the native
16
+ transport profile; its default stays in the transport. Add providers explicitly
17
+ here; there is no plugin framework or dynamic entry-point system.
18
+
19
+ Code Squid -> Core; Code Squid -> Providers -> small Core contracts.
20
+ Core and Providers are separate Python distributions; Providers depends on
21
+ `squid-core==0.1.0`, `openai` and `httpx`, with Python 3.11 or newer required.
22
+ Sibling checkouts support the editable development requirements but are not a
23
+ runtime requirement. Source is under the underscore
24
+ package, tests under tests/, packaging at the root. No compatibility source
25
+ paths remain. Applications persist sparse supported config dictionaries and
26
+ construct providers before injecting them into Core.
27
+
28
+ Public documentation consists of README.md and docs/ARCHITECTURE.md. Private
29
+ development history remains local and ignored by Git. Explicit package discovery
30
+ limits the wheel to squid_providers plus distribution metadata and the MIT license.
31
+ MANIFEST.in adds the two public documents to the source distribution and excludes
32
+ tests, agent instructions, development requirements, private logs and local
33
+ artifacts. Tests and development requirements remain in the Git repository for
34
+ contributors. The first GitHub installation supplies both Core and Providers
35
+ sources explicitly rather than assuming the dependency is published on PyPI.
36
+
37
+ Provider image integration tests cover transport/replay behavior only.
38
+ Behavioral hook checks live in Code Squid alongside its hook implementations;
39
+ Providers has no test or production import dependency on application hooks.
40
+
41
+ Code Squid owns its initial/default provider choice. Providers supplies each
42
+ profile's connection defaults without choosing a backend for applications.
43
+ Only providers.<id> scoped connection configuration is supported; flat model
44
+ connection fields have no readers, migration helpers, or dual-write paths.
45
+ ProviderSettings and normally initialized transports are the current contracts;
46
+ missing constructor-owned fields are not tolerated for old objects or tests.
47
+
48
+ Ollama streaming appends complete native tool-call objects in arrival order,
49
+ including repeated tool names and supplied IDs. It does not merge calls by
50
+ chunk-local positions or guess at name/argument fragments. Native envelopes and
51
+ message field shapes are checked before normalization; validation errors remain
52
+ classifiable through Core, which alone parses and validates tool arguments.
53
+ Both direct and scoped Ollama timeouts must be positive and finite. Native URL
54
+ normalization still removes a trailing /v1 for interoperability.
55
+
56
+ LM Studio metadata requests send a configured bearer credential and remain
57
+ unauthenticated when none exists. Chat readiness requires a loaded LLM, using
58
+ the same type filter as discovery. Image capability behavior stays conservative.
59
+ Interruptible Ollama HTTP errors retain HTTPStatusError and its read response in
60
+ the exception chain, so Core classifies statuses and owns retry policy.
61
+ Both urllib Ollama request paths also chain HTTPError beneath RuntimeError.
62
+ Their consumed response bodies remain in the wrapper message, which Core bounds
63
+ and redacts; urllib failures do not supply a separate response_body_excerpt.
64
+ Regression tests exercise both transport families through Core's shared
65
+ model_request_error_details contract, including the adapter's additional wrapper.
66
+ Fallback OpenAI-compatible tool-call IDs have a response-specific prefix;
67
+ provider-supplied IDs remain unchanged in streaming and non-streaming replies.
68
+
69
+ Streamed usage is best-effort for v0.1: supplied counts are normalized, missing
70
+ counts remain unknown, and transports do not universally request stream_options
71
+ or retry incompatible requests to obtain usage. Cancellation identity and
72
+ transport ownership are unchanged; the two Ollama HTTP implementations remain.
73
+
74
+ ## Normalized model inventory
75
+
76
+ `catalog.discover_model_records(ProviderSettings, debug_log=...)` returns frozen
77
+ `ModelRecord(model_id, display_name=None, loaded=None)` values from
78
+ `squid_providers/discovery.py`. IDs are opaque and case-sensitive; invalid/blank
79
+ IDs are discarded, exact duplicates merged, and results ordered by
80
+ `(model_id.casefold(), model_id)`. Duplicate load state retains True if exposed
81
+ by any row; loaded-row display names take precedence. Unknown metadata is None.
82
+ `discover_models()` delegates to this inventory and returns the same ordered IDs.
83
+
84
+ Discovery owns HTTP/authentication, response parsing, metadata and fallbacks:
85
+ Ollama uses native tags, OpenRouter uses its public compatible catalog, and
86
+ LM Studio/generic compatible servers try native LLM metadata before compatible
87
+ models when native discovery fails or yields no usable LLMs. Squid Models uses
88
+ its compatible catalog. Requests have a 10-second bound. Raw transport enumeration
89
+ keeps native ordering and existing readiness semantics. Applications own labels,
90
+ loaded-first grouping, selected IDs, manual-entry fallback and persistence.
91
+
92
+ OpenRouter image capability comes from exact catalog IDs and
93
+ `architecture.input_modalities` containing `image`, never model-name guesses,
94
+ output modalities or a static model allowlist. Both normalized inventory discovery
95
+ and transport `list_models()` retain those facts in a process-local cache owned by
96
+ `discovery.py`, scoped to base URL and expiring after five minutes. A separately
97
+ constructed runtime transport reuses fresh inventory metadata; manual entry or an
98
+ expired cache uses the existing public `/models` request path. `ModelRecord` keeps
99
+ its presentation-neutral inventory shape; applications need no capability wiring.
100
+ Core's ModelAdapter delegates to the transport, and its ToolExecutor passes the
101
+ decision to `read_file` before image bytes are read. Missing/malformed metadata,
102
+ unknown IDs, discovery failures and genuinely text-only models fail closed.
103
+ Ordinary text reads do not query image capabilities. LM Studio, Ollama and generic
104
+ compatible capability behavior is unchanged.
105
+
106
+
107
+ ## Application-facing external catalog
108
+
109
+ `provider_catalog()` projects existing `ProviderProfile` records into fresh
110
+ JSON-safe records: identity/label, transport, source, supported connection and
111
+ backend config fields, non-secret URL/environment-name defaults and whether a
112
+ user credential is required. It never resolves environment variables or returns
113
+ API keys. Managed Squid Models is excluded; applications compose that product
114
+ entry themselves. The pre-existing managed transport profile remains available
115
+ to runtime/CLI consumers to preserve their inference and discovery semantics.
116
+ Providers imports neither Squid Models nor Desktop.
117
+
118
+ `normalize_connection_config()` merges connection edits with scoped saved config,
119
+ retains secrets on empty form submissions, preserves supported backend options
120
+ and applies credential-field policy. `configuration_status()` reports only boolean
121
+ configuration availability, without network probes. Live readiness stays with
122
+ `provider_ready()`. `resolve_config(require_environment=False)` permits UI and
123
+ preflight checks of a missing credential variable; strict resolution remains the
124
+ default for existing consumers. Desktop delegates to these seams, while Code
125
+ Squid's existing profile consumption remains unchanged.
@@ -0,0 +1,22 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "squid-providers"
7
+ version = "0.1.0"
8
+ description = "First-party model transports, configuration, and discovery for Squid Core"
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ authors = [{name = "Aaron Slater"}]
13
+ requires-python = ">=3.11"
14
+ dependencies = ["squid-core==0.1.0", "openai", "httpx"]
15
+
16
+ [tool.setuptools]
17
+ include-package-data = false
18
+
19
+ [tool.setuptools.packages.find]
20
+ where = ["."]
21
+ namespaces = false
22
+ include = ["squid_providers", "squid_providers.*"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1 @@
1
+ """First-party model transports; import concrete modules explicitly."""
@@ -0,0 +1,86 @@
1
+ """Transport-owned cancellation watcher; Core owns the shared control signal."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import threading
6
+ from collections.abc import Callable
7
+
8
+ from squid_core.providers.base import StreamCancelled
9
+
10
+
11
+ CANCELLATION_POLL_SECONDS = 0.02
12
+ CANCELLATION_MONITOR_JOIN_SECONDS = 0.2
13
+
14
+
15
+ class CancellationMonitor:
16
+ """Close one active transport when a request's cancellation predicate fires.
17
+
18
+ Provider I/O remains on the calling thread. Only this small monitor runs in
19
+ the background, which lets it close a socket/client while the caller is
20
+ blocked waiting for response headers or the next body chunk.
21
+ """
22
+
23
+ def __init__(
24
+ self,
25
+ should_cancel: Callable[[], bool] | None,
26
+ abort: Callable[[], object],
27
+ ) -> None:
28
+ self._should_cancel = should_cancel
29
+ self._abort = abort
30
+ self._stop = threading.Event()
31
+ self._cancelled = threading.Event()
32
+ self._thread: threading.Thread | None = None
33
+
34
+ @property
35
+ def cancelled(self) -> bool:
36
+ return self._cancelled.is_set()
37
+
38
+ def __enter__(self) -> "CancellationMonitor":
39
+ if self._should_cancel is None:
40
+ return self
41
+ if self._should_cancel():
42
+ self._cancelled.set()
43
+ self._abort_safely()
44
+ return self
45
+ self._thread = threading.Thread(
46
+ target=self._watch,
47
+ name="squid-provider-cancellation",
48
+ daemon=True,
49
+ )
50
+ self._thread.start()
51
+ return self
52
+
53
+ def __exit__(self, *_args) -> None:
54
+ self._stop.set()
55
+ if self._thread is not None:
56
+ # The watcher uses Event.wait rather than sleep, so a normal stop
57
+ # wakes it immediately. The bound protects the caller if a foreign
58
+ # transport implements a pathological blocking close method.
59
+ self._thread.join(timeout=CANCELLATION_MONITOR_JOIN_SECONDS)
60
+
61
+ def raise_if_cancelled(self) -> None:
62
+ if self.cancelled or (
63
+ self._should_cancel is not None and self._should_cancel()
64
+ ):
65
+ raise StreamCancelled
66
+
67
+ def _watch(self) -> None:
68
+ while not self._stop.wait(CANCELLATION_POLL_SECONDS):
69
+ try:
70
+ cancelled = bool(self._should_cancel and self._should_cancel())
71
+ except Exception:
72
+ # Cancellation predicates are host control flow. A broken
73
+ # predicate must not replace the active provider request.
74
+ return
75
+ if cancelled:
76
+ self._cancelled.set()
77
+ self._abort_safely()
78
+ return
79
+
80
+ def _abort_safely(self) -> None:
81
+ try:
82
+ self._abort()
83
+ except Exception:
84
+ # The blocked request will surface its own transport error. The
85
+ # cancellation flag remains authoritative at the provider boundary.
86
+ pass