zettcode-models 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,42 @@
1
+ **/.venv/
2
+ **/__pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ build/
6
+ dist/
7
+ .smoke/
8
+ .coverage
9
+ **/.pytest_cache/
10
+ **/.ruff_cache/
11
+ .zett-tool-output/
12
+ .env
13
+ .DS_Store
14
+
15
+ # viztracer writes its trace here by default.
16
+ /result.json
17
+
18
+ # The docs site: dependencies, build output, and VitePress' cache.
19
+ node_modules/
20
+ docs/.vitepress/dist/
21
+ docs/.vitepress/cache/
22
+ docs/.vitepress/.temp/
23
+
24
+ # The TypeScript client is built from its sources; only dist/ is published.
25
+ clients/typescript/dist/
26
+
27
+ # The gateway's page is built from clients/gateway into the package when a distribution is made (`make gateway-ui`);
28
+ # the build output is not kept in the repository. pyproject's `artifacts` puts it in the wheel all the same.
29
+ packages/zettcode-gateway/src/zettcode/gateway/static/
30
+
31
+ # The palette gallery is generated by `make palettes`: every widget painted in
32
+ # every palette, written by docs/scripts/palette_gallery.py. Regenerate it
33
+ # rather than committing a 2 MB copy that goes stale the moment a colour moves.
34
+ docs/internal/palettes.html
35
+
36
+ # The release order is generated from the pyproject.toml files (`make order`); it is not kept in git.
37
+ packages/order.txt
38
+
39
+ # The desktop and phone apps build the gateway's page into their own folders, and electron-builder writes its
40
+ # installers under release/.
41
+ clients/desktop/renderer/
42
+ clients/desktop/release/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Chang-LeHung
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,47 @@
1
+ Metadata-Version: 2.5
2
+ Name: zettcode-models
3
+ Version: 0.1.0
4
+ Summary: A ZettCode plugin: an official model for each vendor API key found in the environment
5
+ Project-URL: Repository, https://github.com/Chang-LeHung/zettcode/tree/main/packages/zettcode-models
6
+ Project-URL: Issues, https://github.com/Chang-LeHung/zettcode/issues
7
+ Author: Chang-LeHung
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: environment,models,plugin,providers,zettcode
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Environment :: Console
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Programming Language :: Python :: 3.15
19
+ Classifier: Topic :: Software Development :: User Interfaces
20
+ Classifier: Typing :: Typed
21
+ Requires-Python: >=3.10
22
+ Requires-Dist: zettcode-plugin-api<0.5,>=0.4
23
+ Description-Content-Type: text/markdown
24
+
25
+ # zettcode-models
26
+
27
+ A ZettCode plugin that offers an **official model** for each vendor whose API key is in the environment:
28
+ OpenAI, Anthropic, DeepSeek and Z.AI.
29
+
30
+ Install it as an extra and enable it once:
31
+
32
+ ```bash
33
+ pip install "zettcode[models]"
34
+ ```
35
+
36
+ ```toml
37
+ [plugins]
38
+ enable = ["models"]
39
+ ```
40
+
41
+ With `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, `DEEPSEEK_API_KEY` or `ZAI_API_KEY` set (`ZHIPUAI_API_KEY` and
42
+ `ZHIPU_API_KEY` are accepted aliases), the plugin registers that host with its current official model — `GPT-6.1 Sol`,
43
+ `Claude Opus 5.5`, `DeepSeek V4.1 Flash` or `GLM-5.3`. The model appears in `/model` with `from the openai plugin`
44
+ (or `anthropic`, `deepseek`, `zai`); its token is read from the environment and never written to `config.toml`.
45
+
46
+ The list is static and no endpoint is called at start. The plugin is off by default: a set of ambient keys should not
47
+ change a model list unless the reader asks it to.
@@ -0,0 +1,23 @@
1
+ # zettcode-models
2
+
3
+ A ZettCode plugin that offers an **official model** for each vendor whose API key is in the environment:
4
+ OpenAI, Anthropic, DeepSeek and Z.AI.
5
+
6
+ Install it as an extra and enable it once:
7
+
8
+ ```bash
9
+ pip install "zettcode[models]"
10
+ ```
11
+
12
+ ```toml
13
+ [plugins]
14
+ enable = ["models"]
15
+ ```
16
+
17
+ With `OPENAI_API_KEY`, `ANTHROPIC_API_KEY`, `DEEPSEEK_API_KEY` or `ZAI_API_KEY` set (`ZHIPUAI_API_KEY` and
18
+ `ZHIPU_API_KEY` are accepted aliases), the plugin registers that host with its current official model — `GPT-6.1 Sol`,
19
+ `Claude Opus 5.5`, `DeepSeek V4.1 Flash` or `GLM-5.3`. The model appears in `/model` with `from the openai plugin`
20
+ (or `anthropic`, `deepseek`, `zai`); its token is read from the environment and never written to `config.toml`.
21
+
22
+ The list is static and no endpoint is called at start. The plugin is off by default: a set of ambient keys should not
23
+ change a model list unless the reader asks it to.
@@ -0,0 +1,59 @@
1
+ [project]
2
+ name = "zettcode-models"
3
+ description = "A ZettCode plugin: an official model for each vendor API key found in the environment"
4
+ readme = "README.md"
5
+ requires-python = ">=3.10"
6
+ dynamic = ["version"]
7
+ license = "MIT"
8
+ license-files = ["LICENSE"]
9
+ authors = [{name = "Chang-LeHung"}]
10
+ keywords = ["zettcode", "plugin", "models", "providers", "environment"]
11
+ classifiers = [
12
+ "Development Status :: 4 - Beta",
13
+ "Environment :: Console",
14
+ "Programming Language :: Python :: 3.10",
15
+ "Programming Language :: Python :: 3.11",
16
+ "Programming Language :: Python :: 3.12",
17
+ "Programming Language :: Python :: 3.13",
18
+ "Programming Language :: Python :: 3.14",
19
+ "Programming Language :: Python :: 3.15",
20
+ "Topic :: Software Development :: User Interfaces",
21
+ "Typing :: Typed",
22
+ ]
23
+ dependencies = [
24
+ # The plugin contract only: the Provider and ProvidedModel the plugin registers, and the PluginContext it activates
25
+ # with. The API this release uses is the one that lets a plugin offer models, new in 0.4.
26
+ "zettcode-plugin-api>=0.4,<0.5",
27
+ ]
28
+
29
+ [project.urls]
30
+ Repository = "https://github.com/Chang-LeHung/zettcode/tree/main/packages/zettcode-models"
31
+ Issues = "https://github.com/Chang-LeHung/zettcode/issues"
32
+
33
+ [project.entry-points."zettcode.plugin"]
34
+ models = "zettcode.models:ModelsPlugin"
35
+
36
+ [tool.zettcode]
37
+ # Published on its own line, installed by a reader who wants it, and off until `[plugins] enable` names it.
38
+ plugin = true
39
+
40
+ [build-system]
41
+ requires = ["hatchling"]
42
+ build-backend = "hatchling.build"
43
+
44
+ [tool.hatch.version]
45
+ path = "src/zettcode/models/__init__.py"
46
+
47
+ [tool.hatch.build.targets.wheel]
48
+ packages = ["src/zettcode"]
49
+
50
+ [tool.hatch.build.targets.sdist]
51
+ include = ["/src", "/tests", "/README.md", "/LICENSE", "/pyproject.toml"]
52
+
53
+ [dependency-groups]
54
+ # What the tests import beyond the plugin itself. The workspace's own dev group carries the same names for `make test`;
55
+ # this one is what the release workflow installs into the fresh environment it tests the built plugin in.
56
+ dev = ["pytest>=8,<9"]
57
+
58
+ [tool.pytest.ini_options]
59
+ testpaths = ["tests"]
@@ -0,0 +1,156 @@
1
+ """Official models for the vendor API keys found in the environment.
2
+
3
+ A reader who has ``OPENAI_API_KEY``, ``ANTHROPIC_API_KEY``, ``DEEPSEEK_API_KEY`` or ``ZAI_API_KEY`` set does not
4
+ have to type an address or a model id to try that vendor. The plugin knows the current official model of each host,
5
+ registers it as one :class:`~zettcode.plugin_api.ProvidedModel`, and leaves the token to the runtime, which reads it
6
+ from the variable named here and never writes it to the configuration.
7
+
8
+ The list is deliberately static: a start asks no vendor for anything, so a key in the environment costs no network
9
+ round trip. It is off by default — ambient keys should not change a model list unless the reader enables the plugin
10
+ with ``[plugins] enable = ["models"]``.
11
+ """
12
+
13
+ from __future__ import annotations
14
+
15
+ import os
16
+ from dataclasses import dataclass
17
+
18
+ from zettcode.plugin_api import Plugin, PluginContext, ProvidedModel, Provider
19
+
20
+ #: The one place the version is written; ``pyproject.toml`` reads it from here.
21
+ __version__ = "0.1.0"
22
+
23
+
24
+ @dataclass(frozen=True, slots=True)
25
+ class Vendor:
26
+ """One host an environment variable can open.
27
+
28
+ Attributes:
29
+ name: The provider name, which is unique across the application.
30
+ label: What a list shows for the host.
31
+ env: The variables that may hold the key, most specific first.
32
+ base_url: The address the client appends its route to.
33
+ api: Which protocol the host speaks.
34
+ model: The vendor's current official model id.
35
+ display: What ``/model`` shows for it.
36
+ context_window: Tokens it can carry.
37
+ multimodal: Whether it takes images.
38
+ """
39
+
40
+ name: str
41
+ label: str
42
+ env: tuple[str, ...]
43
+ base_url: str
44
+ api: str
45
+ model: str
46
+ display: str
47
+ context_window: int
48
+ multimodal: bool = False
49
+
50
+ def key(self) -> tuple[str, str] | None:
51
+ """Return the variable that holds this host's key and the key itself, or ``None`` when none is set."""
52
+ for variable in self.env:
53
+ value = os.getenv(variable)
54
+ if value:
55
+ return variable, value
56
+ return None
57
+
58
+
59
+ #: The official model offered for each host, checked against the vendors' model pages on 2026-11-10. The ids and
60
+ #: windows are the whole of this plugin's knowledge: when a vendor moves on, this table is the one place to edit.
61
+ VENDORS: tuple[Vendor, ...] = (
62
+ Vendor(
63
+ "openai",
64
+ "OpenAI",
65
+ ("OPENAI_API_KEY",),
66
+ "https://api.openai.com/v1",
67
+ "chat",
68
+ "gpt-6.1-sol",
69
+ "GPT-6.1 Sol",
70
+ 1_050_000,
71
+ multimodal=True,
72
+ ),
73
+ Vendor(
74
+ "anthropic",
75
+ "Anthropic",
76
+ ("ANTHROPIC_API_KEY",),
77
+ "https://api.anthropic.com",
78
+ "anthropic",
79
+ "claude-opus-5-5",
80
+ "Claude Opus 5.5",
81
+ 1_000_000,
82
+ multimodal=True,
83
+ ),
84
+ Vendor(
85
+ "deepseek",
86
+ "DeepSeek",
87
+ ("DEEPSEEK_API_KEY",),
88
+ "https://api.deepseek.com",
89
+ "chat",
90
+ "deepseek-v4.1-flash",
91
+ "DeepSeek V4.1 Flash",
92
+ 1_000_000,
93
+ ),
94
+ Vendor(
95
+ "zai",
96
+ "Z.AI",
97
+ ("ZAI_API_KEY", "ZHIPUAI_API_KEY", "ZHIPU_API_KEY"),
98
+ "https://api.z.ai/api/paas/v4",
99
+ "chat",
100
+ "glm-5.3",
101
+ "GLM-5.3",
102
+ 1_000_000,
103
+ ),
104
+ )
105
+
106
+
107
+ def _provider(vendor: Vendor, variable: str) -> Provider:
108
+ """Return the host description for one vendor, with the one model it offers."""
109
+ return Provider(
110
+ vendor.name,
111
+ vendor.label,
112
+ # The vendor names the protocol as the word Provider parses.
113
+ api=vendor.api, # type: ignore[arg-type]
114
+ base_url=vendor.base_url,
115
+ token_env=variable,
116
+ models=(
117
+ ProvidedModel(
118
+ vendor.model,
119
+ display_model=vendor.display,
120
+ context_window=vendor.context_window,
121
+ multimodal=vendor.multimodal,
122
+ ),
123
+ ),
124
+ note="official model",
125
+ )
126
+
127
+
128
+ class ModelsPlugin(Plugin[PluginContext]):
129
+ """Offer one official model for each vendor whose API key is in the environment."""
130
+
131
+ name = "models"
132
+ description = "An official model for each vendor API key in the environment"
133
+
134
+ @classmethod
135
+ def default_enabled(cls) -> bool:
136
+ """Stay off until the reader asks for it: ambient keys should not change a model list by themselves."""
137
+ return False
138
+
139
+ def activate(self, ctx: PluginContext) -> None:
140
+ """Register the host of every key that is set, with its current official model."""
141
+ clashes: list[str] = []
142
+ for vendor in VENDORS:
143
+ key = vendor.key()
144
+ if key is None:
145
+ continue
146
+ try:
147
+ ctx.agent.register_provider(_provider(vendor, key[0]))
148
+ except ValueError as error:
149
+ # A clash is not swallowed: the loader reports this plugin failed, so the reader sees why the host
150
+ # is absent instead of finding it missing with no word. Every clash is named, not only the first.
151
+ clashes.append(f"{vendor.label}: {error}")
152
+ if clashes:
153
+ raise ValueError("; ".join(clashes))
154
+
155
+
156
+ __all__ = ["ModelsPlugin", "Vendor", "VENDORS", "__version__"]
@@ -0,0 +1,123 @@
1
+ """The models plugin: which keys it notices, and the official model each one offers."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import pytest
6
+
7
+ from zettcode.models import VENDORS, ModelsPlugin
8
+ from zettcode.plugin_api import ModelConfig, PluginContext, ZettCodeConfig
9
+
10
+ ALL_ENV = ("OPENAI_API_KEY", "ANTHROPIC_API_KEY", "DEEPSEEK_API_KEY", "ZAI_API_KEY", "ZHIPUAI_API_KEY", "ZHIPU_API_KEY")
11
+
12
+
13
+ def _clear(monkeypatch: pytest.MonkeyPatch) -> None:
14
+ for variable in ALL_ENV:
15
+ monkeypatch.delenv(variable, raising=False)
16
+
17
+
18
+ def _context(tmp_path) -> PluginContext:
19
+ config = ZettCodeConfig(
20
+ workspace=tmp_path, store=tmp_path / "sessions", models=(), harness_dir=tmp_path / "harness"
21
+ )
22
+ return PluginContext(config)
23
+
24
+
25
+ def test_the_plugin_stays_off_until_the_reader_enables_it():
26
+ assert ModelsPlugin.default_enabled() is False
27
+
28
+
29
+ def test_a_key_registers_its_host_and_its_official_model(tmp_path, monkeypatch):
30
+ _clear(monkeypatch)
31
+ monkeypatch.setenv("OPENAI_API_KEY", "sk-test")
32
+ ctx = _context(tmp_path)
33
+
34
+ ModelsPlugin().activate(ctx)
35
+
36
+ (provider,) = ctx.providers
37
+ assert (provider.name, provider.label, provider.token_env) == ("openai", "OpenAI", "OPENAI_API_KEY")
38
+ (model,) = provider.models
39
+ assert model.model == "gpt-6.1-sol" and model.shown_name == "GPT-6.1 Sol"
40
+ assert model.context_window == 1_050_000 and model.multimodal is True
41
+
42
+
43
+ def test_every_vendor_with_a_key_is_registered(tmp_path, monkeypatch):
44
+ _clear(monkeypatch)
45
+ for variable in ("OPENAI_API_KEY", "ANTHROPIC_API_KEY", "DEEPSEEK_API_KEY", "ZAI_API_KEY"):
46
+ monkeypatch.setenv(variable, "sk-test")
47
+ ctx = _context(tmp_path)
48
+
49
+ ModelsPlugin().activate(ctx)
50
+
51
+ assert [provider.name for provider in ctx.providers] == ["openai", "anthropic", "deepseek", "zai"]
52
+ assert next(provider for provider in ctx.providers if provider.name == "anthropic").models[0].model == (
53
+ "claude-opus-5-5"
54
+ )
55
+
56
+
57
+ def test_no_key_registers_nothing(tmp_path, monkeypatch):
58
+ _clear(monkeypatch)
59
+ ctx = _context(tmp_path)
60
+
61
+ ModelsPlugin().activate(ctx)
62
+
63
+ assert ctx.providers == ()
64
+
65
+
66
+ def test_zai_accepts_its_older_variable_and_keeps_the_one_it_found(tmp_path, monkeypatch):
67
+ _clear(monkeypatch)
68
+ monkeypatch.setenv("ZHIPUAI_API_KEY", "sk-test")
69
+ ctx = _context(tmp_path)
70
+
71
+ ModelsPlugin().activate(ctx)
72
+
73
+ (provider,) = ctx.providers
74
+ assert provider.name == "zai" and provider.token_env == "ZHIPUAI_API_KEY"
75
+ assert provider.models[0].model == "glm-5.3"
76
+
77
+
78
+ def test_each_vendor_names_a_model_and_an_address():
79
+ assert {vendor.name for vendor in VENDORS} == {"openai", "anthropic", "deepseek", "zai"}
80
+ assert all(vendor.model and vendor.base_url.startswith("https://") for vendor in VENDORS)
81
+
82
+
83
+ def test_a_shown_name_clash_is_reported_rather_than_silently_skipped(tmp_path, monkeypatch):
84
+ _clear(monkeypatch)
85
+ monkeypatch.setenv("OPENAI_API_KEY", "sk-test")
86
+ config = ZettCodeConfig(
87
+ workspace=tmp_path,
88
+ store=tmp_path / "sessions",
89
+ models=(ModelConfig(model="mine", display_model="GPT-6.1 Sol"),),
90
+ harness_dir=tmp_path / "harness",
91
+ )
92
+ ctx = PluginContext(config)
93
+
94
+ with pytest.raises(ValueError, match="already shown as 'GPT-6.1 Sol'"):
95
+ ModelsPlugin().activate(ctx)
96
+
97
+
98
+ def test_every_clash_is_named_in_one_refusal(tmp_path, monkeypatch):
99
+ _clear(monkeypatch)
100
+ monkeypatch.setenv("OPENAI_API_KEY", "sk-test")
101
+ monkeypatch.setenv("ANTHROPIC_API_KEY", "sk-test")
102
+ config = ZettCodeConfig(
103
+ workspace=tmp_path,
104
+ store=tmp_path / "sessions",
105
+ models=(
106
+ ModelConfig(model="one", display_model="GPT-6.1 Sol"),
107
+ ModelConfig(model="two", display_model="Claude Opus 5.5"),
108
+ ),
109
+ harness_dir=tmp_path / "harness",
110
+ )
111
+
112
+ with pytest.raises(ValueError) as caught:
113
+ ModelsPlugin().activate(PluginContext(config))
114
+
115
+ message = str(caught.value)
116
+ assert "OpenAI" in message and "GPT-6.1 Sol" in message
117
+ assert "Anthropic" in message and "Claude Opus 5.5" in message
118
+
119
+
120
+ def test_the_table_is_internally_consistent():
121
+ assert len({vendor.display for vendor in VENDORS}) == len(VENDORS)
122
+ assert all(vendor.display and vendor.context_window > 0 for vendor in VENDORS)
123
+ assert all(vendor.model != vendor.display for vendor in VENDORS)