seed-kernel 1.0.11__py3-none-any.whl
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.
- seed/__init__.py +125 -0
- seed/cli.py +102 -0
- seed/core/__init__.py +8 -0
- seed/core/_session_cache.py +41 -0
- seed/core/agent_context.py +163 -0
- seed/core/agent_registry.py +180 -0
- seed/core/agent_runtime.py +2384 -0
- seed/core/chat_events.py +70 -0
- seed/core/commands.py +149 -0
- seed/core/config_plane.py +537 -0
- seed/core/engine.py +150 -0
- seed/core/env_access.py +168 -0
- seed/core/execution.py +148 -0
- seed/core/llm_exec.py +1652 -0
- seed/core/llm_presets.py +305 -0
- seed/core/llm_sess.py +1094 -0
- seed/core/media_store.py +84 -0
- seed/core/mem_bridge.py +294 -0
- seed/core/mem_sys.py +409 -0
- seed/core/model_providers.py +88 -0
- seed/core/models.py +211 -0
- seed/core/paths.py +109 -0
- seed/core/persistence.py +133 -0
- seed/core/proj_reg.py +609 -0
- seed/core/proj_todos.py +141 -0
- seed/core/projection_audit.py +317 -0
- seed/core/routing.py +192 -0
- seed/core/sess_store.py +44 -0
- seed/core/tool_output_cap.py +122 -0
- seed/core/tool_runtime.py +330 -0
- seed/core/trace_audit.py +123 -0
- seed/core/turn_loop.py +750 -0
- seed/core/usage_accumulator.py +72 -0
- seed/integrations/__init__.py +33 -0
- seed/integrations/agent_tools.py +160 -0
- seed/integrations/cron_sched.py +773 -0
- seed/integrations/env_config.py +77 -0
- seed/integrations/exec_backend.py +432 -0
- seed/integrations/hooks.py +61 -0
- seed/integrations/hooks_config.py +109 -0
- seed/integrations/instruction_release.py +256 -0
- seed/integrations/lsp_client.py +219 -0
- seed/integrations/lsp_config.py +99 -0
- seed/integrations/mcp_client.py +1283 -0
- seed/integrations/mcp_config.py +208 -0
- seed/integrations/mcp_registry.py +154 -0
- seed/integrations/message_api.py +16 -0
- seed/integrations/prompt_task.py +39 -0
- seed/integrations/safety.py +331 -0
- seed/integrations/session_title.py +211 -0
- seed/integrations/symbol_index.py +311 -0
- seed/integrations/task_runner.py +275 -0
- seed/integrations/webhook_auth.py +33 -0
- seed/integrations/webhook_dedup.py +132 -0
- seed/models.py +31 -0
- seed_kernel-1.0.11.dist-info/METADATA +17 -0
- seed_kernel-1.0.11.dist-info/RECORD +60 -0
- seed_kernel-1.0.11.dist-info/WHEEL +5 -0
- seed_kernel-1.0.11.dist-info/entry_points.txt +2 -0
- seed_kernel-1.0.11.dist-info/top_level.txt +1 -0
seed/core/llm_presets.py
ADDED
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
"""
|
|
2
|
+
LLM Presets Manager - Manage multiple LLM configurations.
|
|
3
|
+
|
|
4
|
+
Presets are stored in ``config/seed.models.json`` as a list of named
|
|
5
|
+
configurations (legacy ``codeagent.models.json`` is still read if the seed file is absent).
|
|
6
|
+
Each preset has::
|
|
7
|
+
|
|
8
|
+
{
|
|
9
|
+
"id": "my-deepseek",
|
|
10
|
+
"name": "DeepSeek V3",
|
|
11
|
+
"provider": "deepseek",
|
|
12
|
+
"base_url": "https://api.deepseek.com/v1",
|
|
13
|
+
"model": "deepseek-v4-flash",
|
|
14
|
+
"api_key": "sk-...",
|
|
15
|
+
"auth_scheme": "Bearer",
|
|
16
|
+
"max_tokens": 8192
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
The default preset ID is stored in ``config/seed.default_model`` (legacy filenames ``seed.models.default.txt`` / ``codeagent.models.default.txt`` supported for reads).
|
|
20
|
+
Resolution order for ``resolve_preset(None)``:
|
|
21
|
+
|
|
22
|
+
1. Preset whose ``id`` matches the stored default (if any).
|
|
23
|
+
2. Else ``SEED_LLM_BASEURL`` / related env vars (if Base URL is non-empty).
|
|
24
|
+
3. Else the **first** preset in the presets file that has both Base URL and model.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
from __future__ import annotations
|
|
28
|
+
|
|
29
|
+
import json
|
|
30
|
+
import logging
|
|
31
|
+
import os
|
|
32
|
+
from pathlib import Path
|
|
33
|
+
from typing import Any, Dict, List, Optional
|
|
34
|
+
|
|
35
|
+
from seed.core import env_access as _ea
|
|
36
|
+
from seed.core.config_plane import project_root
|
|
37
|
+
|
|
38
|
+
logger = logging.getLogger(__name__)
|
|
39
|
+
|
|
40
|
+
PRESETS_FILENAME = "seed.models.json"
|
|
41
|
+
LEGACY_PRESETS_FILENAME = "codeagent.models.json"
|
|
42
|
+
DEFAULT_ID_FILENAME = "seed.default_model"
|
|
43
|
+
LEGACY_DEFAULT_ID_FILENAME_v1 = "codeagent.models.default.txt"
|
|
44
|
+
LEGACY_DEFAULT_ID_FILENAME_v2 = "seed.models.default.txt"
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _config_dir() -> Path:
|
|
48
|
+
cfg = project_root() / "config"
|
|
49
|
+
cfg.mkdir(parents=True, exist_ok=True)
|
|
50
|
+
return cfg
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _presets_read_path() -> Path:
|
|
54
|
+
cfg = _config_dir()
|
|
55
|
+
seed_p = cfg / PRESETS_FILENAME
|
|
56
|
+
leg = cfg / LEGACY_PRESETS_FILENAME
|
|
57
|
+
if seed_p.is_file():
|
|
58
|
+
return seed_p
|
|
59
|
+
if leg.is_file():
|
|
60
|
+
return leg
|
|
61
|
+
return seed_p
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _presets_write_path() -> Path:
|
|
65
|
+
return _config_dir() / PRESETS_FILENAME
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _default_id_read_path() -> Path:
|
|
69
|
+
cfg = _config_dir()
|
|
70
|
+
seed_p = cfg / DEFAULT_ID_FILENAME
|
|
71
|
+
if seed_p.is_file():
|
|
72
|
+
return seed_p
|
|
73
|
+
for leg in (LEGACY_DEFAULT_ID_FILENAME_v1, LEGACY_DEFAULT_ID_FILENAME_v2):
|
|
74
|
+
p = cfg / leg
|
|
75
|
+
if p.is_file():
|
|
76
|
+
return p
|
|
77
|
+
return seed_p
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _default_id_write_path() -> Path:
|
|
81
|
+
return _config_dir() / DEFAULT_ID_FILENAME
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
# ---------------------------------------------------------------------------
|
|
85
|
+
# Load / save presets
|
|
86
|
+
# ---------------------------------------------------------------------------
|
|
87
|
+
|
|
88
|
+
def load_presets() -> List[Dict[str, Any]]:
|
|
89
|
+
path = _presets_read_path()
|
|
90
|
+
if not path.is_file():
|
|
91
|
+
return []
|
|
92
|
+
try:
|
|
93
|
+
raw = path.read_text(encoding="utf-8")
|
|
94
|
+
data = json.loads(raw)
|
|
95
|
+
if isinstance(data, list):
|
|
96
|
+
return [p for p in data if isinstance(p, dict) and p.get("id") != "__default__"]
|
|
97
|
+
if isinstance(data, dict):
|
|
98
|
+
presets = data.get("presets")
|
|
99
|
+
if isinstance(presets, list):
|
|
100
|
+
return [p for p in presets if isinstance(p, dict) and p.get("id") != "__default__"]
|
|
101
|
+
return []
|
|
102
|
+
except (json.JSONDecodeError, OSError) as e:
|
|
103
|
+
logger.warning("Failed to load LLM presets from %s: %s", path, e)
|
|
104
|
+
return []
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def save_presets(presets: List[Dict[str, Any]]) -> None:
|
|
108
|
+
path = _presets_write_path()
|
|
109
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
110
|
+
clean: List[Dict[str, Any]] = []
|
|
111
|
+
seen: set[str] = set()
|
|
112
|
+
for p in presets:
|
|
113
|
+
if not isinstance(p, dict):
|
|
114
|
+
continue
|
|
115
|
+
pid = str(p.get("id") or "").strip()
|
|
116
|
+
if not pid or pid == "__default__":
|
|
117
|
+
continue
|
|
118
|
+
if pid in seen:
|
|
119
|
+
continue
|
|
120
|
+
seen.add(pid)
|
|
121
|
+
entry: Dict[str, Any] = {"id": pid}
|
|
122
|
+
for k in ("name", "base_url", "model", "api_key", "auth_scheme", "provider", "use_type"):
|
|
123
|
+
val = p.get(k)
|
|
124
|
+
if val is not None:
|
|
125
|
+
entry[k] = str(val).strip() if isinstance(val, str) else val
|
|
126
|
+
prov = str(entry.get("provider") or "").strip()
|
|
127
|
+
if prov:
|
|
128
|
+
from seed.core.model_providers import normalize_provider_id
|
|
129
|
+
|
|
130
|
+
entry["provider"] = normalize_provider_id(prov) or prov
|
|
131
|
+
if p.get("supports_vision") is True:
|
|
132
|
+
entry["supports_vision"] = True
|
|
133
|
+
if p.get("supports_image_gen") is True:
|
|
134
|
+
entry["supports_image_gen"] = True
|
|
135
|
+
if p.get("supports_audio") is True:
|
|
136
|
+
entry["supports_audio"] = True
|
|
137
|
+
if p.get("supports_speech") is True:
|
|
138
|
+
entry["supports_speech"] = True
|
|
139
|
+
if p.get("supports_music") is True:
|
|
140
|
+
entry["supports_music"] = True
|
|
141
|
+
if p.get("max_tokens") is not None:
|
|
142
|
+
try:
|
|
143
|
+
entry["max_tokens"] = int(p["max_tokens"])
|
|
144
|
+
except (ValueError, TypeError):
|
|
145
|
+
pass
|
|
146
|
+
clean.append(entry)
|
|
147
|
+
try:
|
|
148
|
+
path.write_text(
|
|
149
|
+
json.dumps(clean, ensure_ascii=False, indent=2) + "\n",
|
|
150
|
+
encoding="utf-8",
|
|
151
|
+
)
|
|
152
|
+
except OSError as e:
|
|
153
|
+
logger.error("Failed to save LLM presets: %s", e)
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
# ---------------------------------------------------------------------------
|
|
157
|
+
# Default preset
|
|
158
|
+
# ---------------------------------------------------------------------------
|
|
159
|
+
|
|
160
|
+
def get_default_preset_id() -> str:
|
|
161
|
+
"""Returns the stored default preset ID, or empty string if none."""
|
|
162
|
+
path = _default_id_read_path()
|
|
163
|
+
if not path.is_file():
|
|
164
|
+
return ""
|
|
165
|
+
try:
|
|
166
|
+
return path.read_text(encoding="utf-8").strip()
|
|
167
|
+
except OSError:
|
|
168
|
+
return ""
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def set_default_preset_id(preset_id: str) -> None:
|
|
172
|
+
"""Persist the default preset ID (empty string clears it)."""
|
|
173
|
+
path = _default_id_write_path()
|
|
174
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
175
|
+
try:
|
|
176
|
+
path.write_text((preset_id or "").strip(), encoding="utf-8")
|
|
177
|
+
except OSError as e:
|
|
178
|
+
logger.error("Failed to save default LLM preset ID: %s", e)
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
# ---------------------------------------------------------------------------
|
|
182
|
+
# Resolve
|
|
183
|
+
# ---------------------------------------------------------------------------
|
|
184
|
+
|
|
185
|
+
def _preset_to_cfg(p: Dict[str, Any]) -> Dict[str, Any]:
|
|
186
|
+
from seed.core.model_providers import resolve_provider_for_preset
|
|
187
|
+
|
|
188
|
+
return {
|
|
189
|
+
"base_url": str(p.get("base_url") or "").rstrip("/"),
|
|
190
|
+
"model": str(p.get("model") or ""),
|
|
191
|
+
"api_key": str(p.get("api_key") or ""),
|
|
192
|
+
"auth_scheme": str(p.get("auth_scheme") or "Bearer"),
|
|
193
|
+
"max_tokens": int(p.get("max_tokens") or 8192),
|
|
194
|
+
"provider": resolve_provider_for_preset(p),
|
|
195
|
+
"supports_vision": p.get("supports_vision") is True,
|
|
196
|
+
"supports_image_gen": p.get("supports_image_gen") is True,
|
|
197
|
+
"supports_audio": p.get("supports_audio") is True,
|
|
198
|
+
"supports_speech": p.get("supports_speech") is True,
|
|
199
|
+
"supports_music": p.get("supports_music") is True,
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def resolve_preset(preset_id: Optional[str]) -> Dict[str, Any]:
|
|
204
|
+
"""
|
|
205
|
+
Resolve a preset ID to an effective config dict.
|
|
206
|
+
See module docstring for ``preset_id`` None / ``__default__`` / env / first-preset rules.
|
|
207
|
+
"""
|
|
208
|
+
presets = load_presets()
|
|
209
|
+
pid = (preset_id or "").strip()
|
|
210
|
+
if not pid or pid == "__default__":
|
|
211
|
+
pid = get_default_preset_id().strip()
|
|
212
|
+
|
|
213
|
+
env_cfg = _env_config_dict()
|
|
214
|
+
|
|
215
|
+
if pid:
|
|
216
|
+
for p in presets:
|
|
217
|
+
if str(p.get("id") or "").strip() == pid:
|
|
218
|
+
return _preset_to_cfg(p)
|
|
219
|
+
|
|
220
|
+
if env_cfg.get("base_url"):
|
|
221
|
+
return env_cfg
|
|
222
|
+
|
|
223
|
+
for p in presets:
|
|
224
|
+
bu = str(p.get("base_url") or "").strip()
|
|
225
|
+
mo = str(p.get("model") or "").strip()
|
|
226
|
+
if bu and mo:
|
|
227
|
+
return _preset_to_cfg(p)
|
|
228
|
+
|
|
229
|
+
return env_cfg
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def llm_executor_from_resolved(cfg: Dict[str, Any]):
|
|
233
|
+
"""Build the process-wide cached ``LLMAPIExecutor`` from ``resolve_preset`` output."""
|
|
234
|
+
from seed.core.llm_exec import get_llm_executor
|
|
235
|
+
|
|
236
|
+
bu = (cfg.get("base_url") or "").strip().rstrip("/")
|
|
237
|
+
mod = (cfg.get("model") or "").strip()
|
|
238
|
+
pk = (cfg.get("api_key") or "").strip()
|
|
239
|
+
scheme = (cfg.get("auth_scheme") or "").strip()
|
|
240
|
+
mt = cfg.get("max_tokens")
|
|
241
|
+
mt_arg = int(mt) if mt is not None else None
|
|
242
|
+
provider = str(cfg.get("provider") or "").strip()
|
|
243
|
+
return get_llm_executor(
|
|
244
|
+
baseURL=bu if bu else None,
|
|
245
|
+
model=mod if mod else None,
|
|
246
|
+
api_key=pk if pk else None,
|
|
247
|
+
auth_scheme=scheme if scheme else None,
|
|
248
|
+
max_tokens=mt_arg,
|
|
249
|
+
provider=provider or None,
|
|
250
|
+
)
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def new_llm_executor_from_preset(preset_id: Optional[str] = None):
|
|
254
|
+
"""Fresh ``LLMAPIExecutor`` instance (safe for concurrent tasks with different presets)."""
|
|
255
|
+
from seed.core.llm_exec import LLMAPIExecutor
|
|
256
|
+
|
|
257
|
+
cfg = resolve_preset(preset_id)
|
|
258
|
+
bu = (cfg.get("base_url") or "").strip().rstrip("/") or "http://127.0.0.1:8000/v1"
|
|
259
|
+
mod = (cfg.get("model") or "").strip() or "mock"
|
|
260
|
+
pk = (cfg.get("api_key") or "").strip() or None
|
|
261
|
+
scheme = (cfg.get("auth_scheme") or "").strip() or "Bearer"
|
|
262
|
+
mt = int(cfg.get("max_tokens") or 8192)
|
|
263
|
+
from seed.core.model_providers import resolve_provider_for_preset
|
|
264
|
+
|
|
265
|
+
provider = resolve_provider_for_preset(
|
|
266
|
+
{
|
|
267
|
+
"provider": cfg.get("provider"),
|
|
268
|
+
"base_url": bu,
|
|
269
|
+
}
|
|
270
|
+
)
|
|
271
|
+
return LLMAPIExecutor(
|
|
272
|
+
baseURL=bu,
|
|
273
|
+
model=mod,
|
|
274
|
+
api_key=pk,
|
|
275
|
+
auth_scheme=scheme,
|
|
276
|
+
maxOutputTokens=mt,
|
|
277
|
+
provider=provider,
|
|
278
|
+
)
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
def _env_config_dict() -> Dict[str, Any]:
|
|
282
|
+
return {
|
|
283
|
+
"base_url": _ea.pick_nonempty(*_ea.LLM_BASEURL).rstrip("/"),
|
|
284
|
+
"model": _ea.pick_default("Qwen/Qwen3.5-35B-A3B-GPTQ-Int4", *_ea.LLM_MODEL),
|
|
285
|
+
"api_key": _ea.pick_nonempty(*_ea.LLM_API_KEY),
|
|
286
|
+
"auth_scheme": (_ea.pick_nonempty(*_ea.LLM_AUTH_SCHEME) or "Bearer"),
|
|
287
|
+
"max_tokens": int(_ea.pick_default("8192", *_ea.LLM_MAX_TOKENS)),
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
# ---------------------------------------------------------------------------
|
|
292
|
+
# Validation
|
|
293
|
+
# ---------------------------------------------------------------------------
|
|
294
|
+
|
|
295
|
+
def _validate_preset(p: Dict[str, Any]) -> Optional[str]:
|
|
296
|
+
pid = str(p.get("id") or "").strip()
|
|
297
|
+
if not pid:
|
|
298
|
+
return "预设 ID 不能为空"
|
|
299
|
+
if pid == "__default__":
|
|
300
|
+
return "ID '__default__' 为保留值"
|
|
301
|
+
if not str(p.get("base_url") or "").strip():
|
|
302
|
+
return "Base URL 不能为空"
|
|
303
|
+
if not str(p.get("model") or "").strip():
|
|
304
|
+
return "模型名称不能为空"
|
|
305
|
+
return None
|