coder-agent 0.1.0__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.
- coder_agent-0.1.0.dist-info/METADATA +262 -0
- coder_agent-0.1.0.dist-info/RECORD +163 -0
- coder_agent-0.1.0.dist-info/WHEEL +5 -0
- coder_agent-0.1.0.dist-info/entry_points.txt +2 -0
- coder_agent-0.1.0.dist-info/licenses/LICENSE.md +21 -0
- coder_agent-0.1.0.dist-info/top_level.txt +1 -0
- coderagent/__init__.py +20 -0
- coderagent/compat/__init__.py +27 -0
- coderagent/compat/cache_control.py +69 -0
- coderagent/compat/config_spec.py +60 -0
- coderagent/compat/exceptions.py +20 -0
- coderagent/compat/retry.py +27 -0
- coderagent/compat/serialize.py +31 -0
- coderagent/config/__init__.py +1 -0
- coderagent/config/defaults.yaml +103 -0
- coderagent/config/loader.py +264 -0
- coderagent/config/schema.py +548 -0
- coderagent/config/writer.py +218 -0
- coderagent/core/__init__.py +1 -0
- coderagent/core/budget.py +47 -0
- coderagent/core/capabilities.py +136 -0
- coderagent/core/checkpoint.py +164 -0
- coderagent/core/content.py +156 -0
- coderagent/core/context.py +618 -0
- coderagent/core/events.py +83 -0
- coderagent/core/history.py +56 -0
- coderagent/core/instructions.py +99 -0
- coderagent/core/loop.py +702 -0
- coderagent/core/memory.py +56 -0
- coderagent/core/mentions.py +81 -0
- coderagent/core/os_sandbox.py +191 -0
- coderagent/core/otel.py +214 -0
- coderagent/core/protocols.py +38 -0
- coderagent/core/redact.py +49 -0
- coderagent/core/sandbox.py +82 -0
- coderagent/core/schema.py +107 -0
- coderagent/core/session.py +344 -0
- coderagent/core/shell_env.py +74 -0
- coderagent/core/subagent.py +474 -0
- coderagent/core/summarize.py +312 -0
- coderagent/core/telemetry.py +209 -0
- coderagent/core/tokens.py +132 -0
- coderagent/core/trust.py +301 -0
- coderagent/environments/__init__.py +11 -0
- coderagent/environments/bubblewrap.py +150 -0
- coderagent/environments/contree.py +146 -0
- coderagent/environments/docker.py +160 -0
- coderagent/environments/local.py +110 -0
- coderagent/environments/singularity.py +138 -0
- coderagent/environments/swerex_docker.py +79 -0
- coderagent/environments/swerex_modal.py +123 -0
- coderagent/eval/__init__.py +1 -0
- coderagent/eval/compare.py +190 -0
- coderagent/eval/report.py +141 -0
- coderagent/eval/runner.py +368 -0
- coderagent/eval/task.py +194 -0
- coderagent/extensions/__init__.py +1 -0
- coderagent/extensions/hooks.py +121 -0
- coderagent/extensions/plugins.py +217 -0
- coderagent/extensions/reflect.py +342 -0
- coderagent/models/__init__.py +33 -0
- coderagent/models/backends.py +218 -0
- coderagent/models/call.py +18 -0
- coderagent/models/check.py +139 -0
- coderagent/models/gateway.py +60 -0
- coderagent/models/litellm_config.py +70 -0
- coderagent/models/provider.py +98 -0
- coderagent/models/reasoning.py +28 -0
- coderagent/models/router.py +136 -0
- coderagent/models/settings.py +172 -0
- coderagent/models/streaming.py +122 -0
- coderagent/models/verbosity.py +14 -0
- coderagent/paths.py +31 -0
- coderagent/run.py +454 -0
- coderagent/skills/__init__.py +119 -0
- coderagent/skills/errors.py +11 -0
- coderagent/skills/install.py +340 -0
- coderagent/skills/presets/code-review/SKILL.md +35 -0
- coderagent/skills/presets/codebase-onboarding/SKILL.md +33 -0
- coderagent/skills/presets/data-analysis/SKILL.md +35 -0
- coderagent/skills/presets/deep-research/SKILL.md +38 -0
- coderagent/skills/presets/frontend-dev/SKILL.md +32 -0
- coderagent/skills/presets/long-document/SKILL.md +37 -0
- coderagent/skills/presets/long-document/scripts/pdf_text.py +37 -0
- coderagent/skills/presets/office-docx/SKILL.md +36 -0
- coderagent/skills/presets/office-docx/scripts/docx_text.py +36 -0
- coderagent/skills/presets/office-pptx/SKILL.md +32 -0
- coderagent/skills/presets/office-xlsx/SKILL.md +34 -0
- coderagent/skills/presets/office-xlsx/scripts/xlsx_text.py +72 -0
- coderagent/skills/presets/writing/SKILL.md +31 -0
- coderagent/skills/sandbox.py +269 -0
- coderagent/skills/sites.py +177 -0
- coderagent/skills/source.py +404 -0
- coderagent/testing/__init__.py +5 -0
- coderagent/testing/factory.py +59 -0
- coderagent/testing/scripted_model.py +54 -0
- coderagent/tools/__init__.py +1 -0
- coderagent/tools/base.py +54 -0
- coderagent/tools/bash_policy.py +486 -0
- coderagent/tools/builtin/__init__.py +35 -0
- coderagent/tools/builtin/fs.py +283 -0
- coderagent/tools/builtin/patch.py +279 -0
- coderagent/tools/builtin/search.py +242 -0
- coderagent/tools/builtin/shell.py +336 -0
- coderagent/tools/builtin/skill.py +41 -0
- coderagent/tools/builtin/task.py +53 -0
- coderagent/tools/builtin/todo.py +63 -0
- coderagent/tools/executor.py +243 -0
- coderagent/tools/mcp.py +317 -0
- coderagent/tools/permissions.py +472 -0
- coderagent/tools/registry.py +83 -0
- coderagent/tools/rules.py +138 -0
- coderagent/ui/__init__.py +1 -0
- coderagent/ui/cli.py +498 -0
- coderagent/ui/commands/__init__.py +109 -0
- coderagent/ui/commands/builtin.py +778 -0
- coderagent/ui/commands/compact.py +12 -0
- coderagent/ui/commands/resume.py +26 -0
- coderagent/ui/commands/review.py +73 -0
- coderagent/ui/commands/rewind.py +28 -0
- coderagent/ui/custom_commands.py +179 -0
- coderagent/ui/notify.py +46 -0
- coderagent/ui/open_file.py +48 -0
- coderagent/ui/render.py +62 -0
- coderagent/ui/spinner.py +68 -0
- coderagent/ui/tui.py +610 -0
- coderagent/ui/widgets/__init__.py +29 -0
- coderagent/ui/widgets/approval_prompt.py +129 -0
- coderagent/ui/widgets/diff_view.py +97 -0
- coderagent/ui/widgets/file_tree.py +105 -0
- coderagent/ui/widgets/markdown_message.py +44 -0
- coderagent/ui/widgets/markup.py +10 -0
- coderagent/ui/widgets/message_block.py +61 -0
- coderagent/ui/widgets/path_suggester.py +66 -0
- coderagent/ui/widgets/session_picker.py +49 -0
- coderagent/ui/widgets/status_bar.py +44 -0
- coderagent/ui/widgets/todo_panel.py +40 -0
- coderagent/ui/widgets/tool_card.py +104 -0
- coderagent/ui/widgets/working_dots.py +26 -0
- coderagent/version.py +7 -0
- coderagent/web/__init__.py +5 -0
- coderagent/web/api.py +449 -0
- coderagent/web/app.py +113 -0
- coderagent/web/approver.py +73 -0
- coderagent/web/config_api.py +53 -0
- coderagent/web/events.py +159 -0
- coderagent/web/files.py +115 -0
- coderagent/web/i18n.py +346 -0
- coderagent/web/server.py +100 -0
- coderagent/web/sessions.py +404 -0
- coderagent/web/skills_api.py +376 -0
- coderagent/web/static/app.css +283 -0
- coderagent/web/static/app.js +1466 -0
- coderagent/web/templates/en/base.html +31 -0
- coderagent/web/templates/en/chat.html +60 -0
- coderagent/web/templates/en/macros.html +9 -0
- coderagent/web/templates/en/settings.html +80 -0
- coderagent/web/templates/en/skills.html +64 -0
- coderagent/web/templates/zh/base.html +31 -0
- coderagent/web/templates/zh/chat.html +60 -0
- coderagent/web/templates/zh/macros.html +9 -0
- coderagent/web/templates/zh/settings.html +77 -0
- coderagent/web/templates/zh/skills.html +61 -0
coderagent/web/i18n.py
ADDED
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
"""The language of the pages: Chinese for a Chinese region, English everywhere else.
|
|
2
|
+
|
|
3
|
+
The region of the visitor comes from the proxy in front of the server, or from
|
|
4
|
+
a geoip database. The visitor can always say which language they want: with
|
|
5
|
+
`?lang=zh` or with the box in the top bar, which remembers it in a cookie.
|
|
6
|
+
|
|
7
|
+
A language is added in three places: its templates in `templates/<code>/`, its
|
|
8
|
+
strings in `STRINGS` and its entry in `LANGUAGES`. A language that has no
|
|
9
|
+
templates is not offered.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import os
|
|
13
|
+
from collections.abc import Sequence
|
|
14
|
+
from dataclasses import dataclass
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
from typing import Any
|
|
17
|
+
|
|
18
|
+
from coderagent.paths import config_home
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@dataclass(frozen=True)
|
|
22
|
+
class Language:
|
|
23
|
+
"""A language of the pages."""
|
|
24
|
+
|
|
25
|
+
code: str
|
|
26
|
+
"""The code of the language: `en`, `zh`."""
|
|
27
|
+
|
|
28
|
+
name: str
|
|
29
|
+
"""The name of the language in that language: `English`, `中文`."""
|
|
30
|
+
|
|
31
|
+
english: str
|
|
32
|
+
"""The name of the language in English: `English`, `Chinese`."""
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
LANGUAGES: tuple[Language, ...] = (
|
|
36
|
+
Language("en", "English", "English"),
|
|
37
|
+
Language("zh", "中文", "Chinese"),
|
|
38
|
+
)
|
|
39
|
+
"""The languages of the pages. One is only offered when its templates are there."""
|
|
40
|
+
|
|
41
|
+
REGION_LANGUAGES = {
|
|
42
|
+
"CN": "zh",
|
|
43
|
+
"HK": "zh",
|
|
44
|
+
"MO": "zh",
|
|
45
|
+
"TW": "zh",
|
|
46
|
+
"JP": "ja",
|
|
47
|
+
"FR": "fr",
|
|
48
|
+
"DE": "de",
|
|
49
|
+
}
|
|
50
|
+
"""The language of a region. A region whose language is not offered falls back to the browser."""
|
|
51
|
+
|
|
52
|
+
COUNTRY_HEADERS = ("CF-IPCountry", "X-AppEngine-Country", "X-Vercel-IP-Country", "X-Country-Code")
|
|
53
|
+
"""The headers a proxy in front of the server sets the country in."""
|
|
54
|
+
|
|
55
|
+
UNKNOWN_COUNTRIES = ("XX", "T1", "")
|
|
56
|
+
"""The values a proxy puts there when it does not know the country."""
|
|
57
|
+
|
|
58
|
+
GEOIP_ENV = "CODERAGENT_GEOIP_DB"
|
|
59
|
+
"""Where the geoip database is, if it is not in the config home."""
|
|
60
|
+
|
|
61
|
+
COOKIE = "coder_lang"
|
|
62
|
+
"""The cookie that holds the language the visitor chose."""
|
|
63
|
+
|
|
64
|
+
DEFAULT_LANGUAGE = "en"
|
|
65
|
+
"""The language of the pages when nothing else says which one."""
|
|
66
|
+
|
|
67
|
+
STRINGS: dict[str, dict[str, str]] = {
|
|
68
|
+
"en": {
|
|
69
|
+
"history": "earlier turns",
|
|
70
|
+
"earlier_turns": "{count} earlier turns",
|
|
71
|
+
"rewritten": "the agent was given: {text}",
|
|
72
|
+
"tool": "tool",
|
|
73
|
+
"approval": "approval: {tool}",
|
|
74
|
+
"allow": "Allow",
|
|
75
|
+
"deny": "Deny",
|
|
76
|
+
"always": "Always allow",
|
|
77
|
+
"answered": "answered…",
|
|
78
|
+
"error": "error: {message}",
|
|
79
|
+
"image_bad_type": "error: that file is not an image a model takes (png, jpg, gif, webp)",
|
|
80
|
+
"image_too_big": "error: the image is too big (5 MB is the limit)",
|
|
81
|
+
"attach_image": "Add a picture",
|
|
82
|
+
"remove_image": "remove",
|
|
83
|
+
"no_answer": "no answer: denied",
|
|
84
|
+
"answered_decision": "answered: {decision}",
|
|
85
|
+
"compacted": "the context was compacted ({tokens} tokens)",
|
|
86
|
+
"recapped": "the conversation was summarized, nothing was dropped",
|
|
87
|
+
"side_conversation": "that answer came from a conversation that goes aside",
|
|
88
|
+
"verified": "the check ran, {failed} command(s) did not pass",
|
|
89
|
+
"review": "the changes that are being reviewed",
|
|
90
|
+
"untracked": "new files: {files}",
|
|
91
|
+
"settled": "the session was settled in the memory (${cost})",
|
|
92
|
+
"settled_unpriced": "the session was settled in the memory (this model has no price)",
|
|
93
|
+
"rolled_back": "the conversation was rolled back to {messages} messages",
|
|
94
|
+
"stop_max_turns": "the turn was cut off: it reached the ceiling of {calls} model calls",
|
|
95
|
+
"stop_cost_exceeded": "the turn stopped: the budget of the session is spent",
|
|
96
|
+
"stop_token_limit": "the turn stopped: the token limit of the session is reached",
|
|
97
|
+
"stop_interrupted": "the turn was stopped",
|
|
98
|
+
"mode_default": "Every tool that changes something asks for approval.",
|
|
99
|
+
"mode_acceptEdits": "The writes go through, everything else asks for approval.",
|
|
100
|
+
"mode_plan": "Read only: the agent looks around and writes down the plan.",
|
|
101
|
+
"mode_readonly": "Read only: the agent looks around and answers.",
|
|
102
|
+
"mode_bypass": "Nothing is asked: every tool call is allowed. For unattended runs.",
|
|
103
|
+
"bypass_confirm": "Bypass mode asks nothing: every tool call goes through. Turn it on?",
|
|
104
|
+
"from": "from: {source}",
|
|
105
|
+
"server_mode": "The server was started with --permission-mode {mode}: the mode of the file does not decide anything.",
|
|
106
|
+
"saved": "saved to {path}",
|
|
107
|
+
"no_key": "no key is set",
|
|
108
|
+
"not_set": "not set",
|
|
109
|
+
"provider_is": "the provider is {provider}",
|
|
110
|
+
"key_source_settings": "the settings",
|
|
111
|
+
"key_source_env": "the environment ({var})",
|
|
112
|
+
"key_set": "set ({hint}) — click to show it",
|
|
113
|
+
"key_not_set": "not set — click to show it",
|
|
114
|
+
"testing": "trying the model out…",
|
|
115
|
+
"test_latency": "latency: {ms} ms",
|
|
116
|
+
"test_cost": "cost: {cost}",
|
|
117
|
+
"test_tools_ok": "the model calls the tools",
|
|
118
|
+
"test_tools_bad": "the tools do not work: {message}",
|
|
119
|
+
"field_api_base": "api base",
|
|
120
|
+
"field_session_id": "session id",
|
|
121
|
+
"field_model": "model",
|
|
122
|
+
"field_tokens": "tokens",
|
|
123
|
+
"field_window": "window",
|
|
124
|
+
"field_cost": "cost",
|
|
125
|
+
"field_priced": "has a price",
|
|
126
|
+
"field_cwd": "directory",
|
|
127
|
+
"field_mode": "mode",
|
|
128
|
+
"field_state": "state",
|
|
129
|
+
"field_sandbox": "sandbox",
|
|
130
|
+
"field_busy": "busy",
|
|
131
|
+
"turns": "{count} model calls",
|
|
132
|
+
"no_limit": "no limit",
|
|
133
|
+
"turn_ceiling": "the configuration holds every sub agent to {count} model calls",
|
|
134
|
+
"skills_none": "no skills installed yet",
|
|
135
|
+
"skills_prev": "‹",
|
|
136
|
+
"skills_next": "›",
|
|
137
|
+
"skills_page": "page {page} of {count}",
|
|
138
|
+
"skills_from": "from {source}",
|
|
139
|
+
"skills_files": "{count} file(s)",
|
|
140
|
+
"skills_sha256": "sha256",
|
|
141
|
+
"skills_yours": "this one is yours: it was not installed from here",
|
|
142
|
+
"skills_details": "Details",
|
|
143
|
+
"skills_update": "Check for an update",
|
|
144
|
+
"skills_uninstall": "Uninstall",
|
|
145
|
+
"skills_registries": "Known registries",
|
|
146
|
+
"skills_use": "Use this one",
|
|
147
|
+
"skills_up_to_date": "{name} is up to date",
|
|
148
|
+
"skills_removed": "{name} was removed",
|
|
149
|
+
"skills_installed_ok": "{name} is installed. It takes effect in a new session.",
|
|
150
|
+
"skills_uninstall_confirm": "Remove {name}?",
|
|
151
|
+
"skills_downloading": "downloading…",
|
|
152
|
+
"skills_site_official_name": "Gitee official",
|
|
153
|
+
"skills_site_official": "The repository of Gitee itself: the skills that drive the Gitee MCP server.",
|
|
154
|
+
"skills_site_personal_name": "Personal collection",
|
|
155
|
+
"skills_site_personal": "A collection of everyday skills: memory, tests, the work of a developer.",
|
|
156
|
+
"skills_site_tools_name": "Everyday tools",
|
|
157
|
+
"skills_site_tools": "A few small ones: reading a codebase, deploying, asking a model about itself.",
|
|
158
|
+
"skills_site_download": "Download",
|
|
159
|
+
"skills_site_loading": "loading the site…",
|
|
160
|
+
"skills_site_count": "{count} skills",
|
|
161
|
+
"skills_site_sync": "Sync",
|
|
162
|
+
"skills_site_syncing": "fetching the site again…",
|
|
163
|
+
"skills_site_installed": "installed",
|
|
164
|
+
"skills_site_empty": "this site has no skills",
|
|
165
|
+
"skills_site_prev": "‹",
|
|
166
|
+
"skills_site_next": "›",
|
|
167
|
+
"skills_site_page": "page {page} of {count}",
|
|
168
|
+
},
|
|
169
|
+
"zh": {
|
|
170
|
+
"history": "之前的几轮",
|
|
171
|
+
"earlier_turns": "之前的 {count} 轮",
|
|
172
|
+
"rewritten": "给 agent 的是:{text}",
|
|
173
|
+
"tool": "工具",
|
|
174
|
+
"approval": "审批:{tool}",
|
|
175
|
+
"allow": "允许",
|
|
176
|
+
"deny": "拒绝",
|
|
177
|
+
"always": "始终允许",
|
|
178
|
+
"answered": "已回答…",
|
|
179
|
+
"error": "错误:{message}",
|
|
180
|
+
"image_bad_type": "错误:那个文件不是模型收的图片(png、jpg、gif、webp)",
|
|
181
|
+
"image_too_big": "错误:图片太大了(上限 5 MB)",
|
|
182
|
+
"attach_image": "加一张图片",
|
|
183
|
+
"remove_image": "移除",
|
|
184
|
+
"no_answer": "没有回答:已拒绝",
|
|
185
|
+
"answered_decision": "已回答:{decision}",
|
|
186
|
+
"compacted": "上下文已压缩({tokens} tokens)",
|
|
187
|
+
"recapped": "对话已总结,什么都没有丢掉",
|
|
188
|
+
"side_conversation": "这个回答来自一段岔开的对话",
|
|
189
|
+
"verified": "校验已运行,{failed} 条命令没有通过",
|
|
190
|
+
"review": "正在评审的改动",
|
|
191
|
+
"untracked": "新文件:{files}",
|
|
192
|
+
"settled": "会话已写入记忆(${cost})",
|
|
193
|
+
"settled_unpriced": "会话已写入记忆(这个模型没有价格)",
|
|
194
|
+
"rolled_back": "对话已回滚到 {messages} 条消息",
|
|
195
|
+
"stop_max_turns": "这一轮被切断了:模型调用到了上限 {calls} 次",
|
|
196
|
+
"stop_cost_exceeded": "这一轮停了:会话的预算用完了",
|
|
197
|
+
"stop_token_limit": "这一轮停了:会话的 token 上限到了",
|
|
198
|
+
"stop_interrupted": "这一轮被停掉了",
|
|
199
|
+
"mode_default": "凡是会改东西的工具都要审批。",
|
|
200
|
+
"mode_acceptEdits": "写操作直接放行,其余的还是要问。",
|
|
201
|
+
"mode_plan": "只读:agent 只看不改,把计划写出来。",
|
|
202
|
+
"mode_readonly": "只读:agent 只看不改,把看到的说出来。",
|
|
203
|
+
"mode_bypass": "一律不问,所有工具调用都放行——无人值守跑的时候用。",
|
|
204
|
+
"bypass_confirm": "bypass 模式一律不问,所有工具调用都放行。要打开吗?",
|
|
205
|
+
"from": "来自:{source}",
|
|
206
|
+
"server_mode": "服务端是用 --permission-mode {mode} 起的:文件里的模式不作数。",
|
|
207
|
+
"saved": "已保存到 {path}",
|
|
208
|
+
"no_key": "没有设置 key",
|
|
209
|
+
"not_set": "没设置",
|
|
210
|
+
"provider_is": "厂商是 {provider}",
|
|
211
|
+
"key_source_settings": "设置",
|
|
212
|
+
"key_source_env": "环境变量({var})",
|
|
213
|
+
"key_set": "已设置({hint})——点一下显示",
|
|
214
|
+
"key_not_set": "没设置——点一下显示",
|
|
215
|
+
"testing": "正在试这个模型…",
|
|
216
|
+
"test_latency": "延迟:{ms} 毫秒",
|
|
217
|
+
"test_cost": "花费:{cost}",
|
|
218
|
+
"test_tools_ok": "模型会调用工具",
|
|
219
|
+
"test_tools_bad": "工具用不了:{message}",
|
|
220
|
+
"field_api_base": "接口地址",
|
|
221
|
+
"field_session_id": "会话 id",
|
|
222
|
+
"field_model": "模型",
|
|
223
|
+
"field_tokens": "token 数",
|
|
224
|
+
"field_window": "上下文窗口",
|
|
225
|
+
"field_cost": "花费",
|
|
226
|
+
"field_priced": "有价格",
|
|
227
|
+
"field_cwd": "目录",
|
|
228
|
+
"field_mode": "模式",
|
|
229
|
+
"field_state": "状态",
|
|
230
|
+
"field_sandbox": "沙箱",
|
|
231
|
+
"field_busy": "正忙",
|
|
232
|
+
"turns": "{count} 次模型调用",
|
|
233
|
+
"no_limit": "不限",
|
|
234
|
+
"turn_ceiling": "配置把所有子 agent 压到 {count} 次模型调用",
|
|
235
|
+
"skills_none": "还没有装任何技能",
|
|
236
|
+
"skills_prev": "‹",
|
|
237
|
+
"skills_next": "›",
|
|
238
|
+
"skills_page": "第 {page} 页,共 {count} 页",
|
|
239
|
+
"skills_from": "来自 {source}",
|
|
240
|
+
"skills_files": "{count} 个文件",
|
|
241
|
+
"skills_sha256": "sha256",
|
|
242
|
+
"skills_yours": "这个是你自己的,不是这里装的",
|
|
243
|
+
"skills_details": "详情",
|
|
244
|
+
"skills_update": "检查更新",
|
|
245
|
+
"skills_uninstall": "卸载",
|
|
246
|
+
"skills_registries": "已知的注册表",
|
|
247
|
+
"skills_use": "用它",
|
|
248
|
+
"skills_up_to_date": "{name} 已经是最新的了",
|
|
249
|
+
"skills_removed": "{name} 已经删掉了",
|
|
250
|
+
"skills_installed_ok": "{name} 装好了,新会话里生效。",
|
|
251
|
+
"skills_uninstall_confirm": "要删掉 {name} 吗?",
|
|
252
|
+
"skills_downloading": "下载中…",
|
|
253
|
+
"skills_site_official_name": "Gitee 官方",
|
|
254
|
+
"skills_site_official": "Gitee 官方仓库:驱动 Gitee MCP 服务器的那些技能。",
|
|
255
|
+
"skills_site_personal_name": "个人收藏",
|
|
256
|
+
"skills_site_personal": "个人整理的合集:记忆同步、测试生成、开发流程这些日常用得上的技能。",
|
|
257
|
+
"skills_site_tools_name": "日常工具",
|
|
258
|
+
"skills_site_tools": "几个小而全的技能:读代码库、部署、查模型信息这类活儿。",
|
|
259
|
+
"skills_site_download": "下载",
|
|
260
|
+
"skills_site_loading": "正在取这个站点…",
|
|
261
|
+
"skills_site_count": "{count} 个技能",
|
|
262
|
+
"skills_site_sync": "同步更新",
|
|
263
|
+
"skills_site_syncing": "正在重新取这个站点…",
|
|
264
|
+
"skills_site_installed": "已安装",
|
|
265
|
+
"skills_site_empty": "这个站点里没有技能",
|
|
266
|
+
"skills_site_prev": "‹",
|
|
267
|
+
"skills_site_next": "›",
|
|
268
|
+
"skills_site_page": "第 {page} 页,共 {count} 页",
|
|
269
|
+
},
|
|
270
|
+
}
|
|
271
|
+
"""The strings the browser shows. The templates have their own text."""
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def country_of(request: Any) -> str:
|
|
275
|
+
"""The country of the visitor: the header of the proxy, or the geoip database."""
|
|
276
|
+
for header in COUNTRY_HEADERS:
|
|
277
|
+
value = request.headers.get(header, "").strip().upper()
|
|
278
|
+
if value and value not in UNKNOWN_COUNTRIES:
|
|
279
|
+
return value
|
|
280
|
+
return _geoip_country(request.client.host if request.client else "")
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
_READER: Any = None
|
|
284
|
+
"""The geoip database, opened once."""
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
def _geoip_country(address: str) -> str:
|
|
288
|
+
"""The country of an address, with the geoip database, if there is one."""
|
|
289
|
+
global _READER
|
|
290
|
+
try:
|
|
291
|
+
import geoip2.database
|
|
292
|
+
import geoip2.errors
|
|
293
|
+
except ImportError:
|
|
294
|
+
return ""
|
|
295
|
+
if _READER is None:
|
|
296
|
+
path = Path(os.getenv(GEOIP_ENV) or config_home() / "GeoLite2-Country.mmdb")
|
|
297
|
+
if not path.is_file():
|
|
298
|
+
return ""
|
|
299
|
+
_READER = geoip2.database.Reader(str(path))
|
|
300
|
+
try:
|
|
301
|
+
return _READER.country(address).country.iso_code or ""
|
|
302
|
+
except geoip2.errors.AddressNotFoundError:
|
|
303
|
+
return ""
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
def _preferred_language(header: str, available: Sequence[str]) -> str:
|
|
307
|
+
"""The language of the `accept-language` header, the one with the best quality."""
|
|
308
|
+
best, quality = "", 0.0
|
|
309
|
+
for part in header.split(","):
|
|
310
|
+
name, _, parameters = part.strip().partition(";")
|
|
311
|
+
weight = 1.0
|
|
312
|
+
for parameter in parameters.split(";"):
|
|
313
|
+
key, _, value = parameter.strip().partition("=")
|
|
314
|
+
if key == "q":
|
|
315
|
+
weight = float(value or 0)
|
|
316
|
+
code = name.strip().lower().split("-")[0]
|
|
317
|
+
if code in available and weight > quality:
|
|
318
|
+
best, quality = code, weight
|
|
319
|
+
return best
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
def _fallback(available: Sequence[str]) -> str:
|
|
323
|
+
"""The language of the pages when nothing else says which one."""
|
|
324
|
+
if DEFAULT_LANGUAGE in available:
|
|
325
|
+
return DEFAULT_LANGUAGE
|
|
326
|
+
return available[0] if available else DEFAULT_LANGUAGE
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
def locale_of(request: Any, available: Sequence[str] = (DEFAULT_LANGUAGE,)) -> str:
|
|
330
|
+
"""The language of the pages.
|
|
331
|
+
|
|
332
|
+
The choice of the visitor comes first (`?lang=` and the cookie of the
|
|
333
|
+
button in the top bar), then the region of the address, then the language
|
|
334
|
+
the browser asks for. A language that is not offered is ignored.
|
|
335
|
+
"""
|
|
336
|
+
choice = request.query_params.get("lang", "").strip().lower()
|
|
337
|
+
if choice in available:
|
|
338
|
+
return choice
|
|
339
|
+
cookie = request.cookies.get(COOKIE, "")
|
|
340
|
+
if cookie in available:
|
|
341
|
+
return cookie
|
|
342
|
+
country = country_of(request)
|
|
343
|
+
if country:
|
|
344
|
+
language = REGION_LANGUAGES.get(country, "")
|
|
345
|
+
return language if language in available else _fallback(available)
|
|
346
|
+
return _preferred_language(request.headers.get("accept-language", ""), available) or _fallback(available)
|
coderagent/web/server.py
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"""The uvicorn entry point of the web interface."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
import socket
|
|
5
|
+
import sys
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from coderagent.config.loader import load_config
|
|
9
|
+
from coderagent.core.protocols import ModelBackend
|
|
10
|
+
from coderagent.models import warm_up_litellm
|
|
11
|
+
|
|
12
|
+
logger = logging.getLogger("coderagent.web")
|
|
13
|
+
|
|
14
|
+
LOOPBACK = ("127.0.0.1", "localhost", "::1")
|
|
15
|
+
"""The addresses that only the user of the machine can reach."""
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def check_address(host: str, port: int) -> None:
|
|
19
|
+
"""Make sure the address is free before the server says it is listening.
|
|
20
|
+
|
|
21
|
+
A port that is already taken is the most common way for the server to fail,
|
|
22
|
+
and the error of uvicorn does not say what to do about it.
|
|
23
|
+
"""
|
|
24
|
+
with socket.socket() as probe:
|
|
25
|
+
probe.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
|
26
|
+
"""A server that was stopped leaves the port in `TIME_WAIT`: the port is free."""
|
|
27
|
+
try:
|
|
28
|
+
probe.bind((host, port))
|
|
29
|
+
except OSError as error:
|
|
30
|
+
print(
|
|
31
|
+
f"coder web: cannot listen on {host}:{port} ({error.strerror}).\n"
|
|
32
|
+
f" Another program is using that port. Try another one: --port {port + 1}",
|
|
33
|
+
file=sys.stderr,
|
|
34
|
+
)
|
|
35
|
+
raise SystemExit(1) from error
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def serve(
|
|
39
|
+
cwd: Path,
|
|
40
|
+
host: str = "127.0.0.1",
|
|
41
|
+
port: int = 8765,
|
|
42
|
+
config_spec: list[str] | None = None,
|
|
43
|
+
model: ModelBackend | None = None,
|
|
44
|
+
permission_mode: str | None = None,
|
|
45
|
+
) -> None:
|
|
46
|
+
"""Start the web interface and serve it until the user stops it."""
|
|
47
|
+
import uvicorn
|
|
48
|
+
|
|
49
|
+
from coderagent.web.app import create_app
|
|
50
|
+
|
|
51
|
+
warm_up_litellm()
|
|
52
|
+
"""litellm loads in the background, and its banners must not reach the event stream."""
|
|
53
|
+
config = load_config(config_spec or [], cwd=cwd)
|
|
54
|
+
app = create_app(
|
|
55
|
+
config,
|
|
56
|
+
cwd,
|
|
57
|
+
model=model,
|
|
58
|
+
config_spec=config_spec or [],
|
|
59
|
+
permission_mode=permission_mode,
|
|
60
|
+
)
|
|
61
|
+
if host not in LOOPBACK:
|
|
62
|
+
logger.warning(
|
|
63
|
+
"The web interface listens on %s: everybody who can reach that address can drive the agent.",
|
|
64
|
+
host,
|
|
65
|
+
)
|
|
66
|
+
check_address(host, port)
|
|
67
|
+
print(f"coder web: http://{host}:{port}", flush=True)
|
|
68
|
+
config = uvicorn.Config(
|
|
69
|
+
app,
|
|
70
|
+
host=host,
|
|
71
|
+
port=port,
|
|
72
|
+
log_level="info",
|
|
73
|
+
access_log=False,
|
|
74
|
+
timeout_graceful_shutdown=5,
|
|
75
|
+
)
|
|
76
|
+
"""The log is at info, so that the server says what it waits for.
|
|
77
|
+
|
|
78
|
+
A browser tab holds the event stream open. Without a deadline the server
|
|
79
|
+
waits for that connection forever, and the signal that stops it does not
|
|
80
|
+
reach it: the stream has to end first, and it only ends when the browser
|
|
81
|
+
goes away. The access log is off: one line per request drowns the messages
|
|
82
|
+
that matter.
|
|
83
|
+
"""
|
|
84
|
+
|
|
85
|
+
class Server(uvicorn.Server):
|
|
86
|
+
"""A server that lets the browsers go before it stops."""
|
|
87
|
+
|
|
88
|
+
def handle_exit(self, sig: int, frame: object) -> None:
|
|
89
|
+
"""The streams of the sessions end first.
|
|
90
|
+
|
|
91
|
+
The server waits for its connections before it stops. The event
|
|
92
|
+
stream of a browser tab is one of them, and it never ends by
|
|
93
|
+
itself: the server has to end it, or it waits until the deadline
|
|
94
|
+
and cancels it, which it reports as an error.
|
|
95
|
+
"""
|
|
96
|
+
for runtime in app.state.registry.runtimes():
|
|
97
|
+
runtime.end_streams()
|
|
98
|
+
super().handle_exit(sig, frame)
|
|
99
|
+
|
|
100
|
+
Server(config=config).run()
|