tagword-codeagent 1.1.6__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.
Files changed (173) hide show
  1. codeagent/__init__.py +10 -0
  2. codeagent/__main__.py +13 -0
  3. codeagent/cli/__init__.py +13 -0
  4. codeagent/cli/entrypoint.py +161 -0
  5. codeagent/cli/main.py +979 -0
  6. codeagent/core/__init__.py +2 -0
  7. codeagent/core/attachments.py +342 -0
  8. codeagent/core/audio_models.py +50 -0
  9. codeagent/core/bootstrap.py +178 -0
  10. codeagent/core/default_presets.py +159 -0
  11. codeagent/core/env.py +106 -0
  12. codeagent/core/folder_picker.py +151 -0
  13. codeagent/core/image_understanding.py +90 -0
  14. codeagent/core/models.py +6 -0
  15. codeagent/core/paths.py +238 -0
  16. codeagent/core/pricing.py +107 -0
  17. codeagent/core/process_ports.py +258 -0
  18. codeagent/core/seed_bridge.py +21 -0
  19. codeagent/core/settings.py +98 -0
  20. codeagent/core/speech_synth.py +330 -0
  21. codeagent/core/team_config.py +247 -0
  22. codeagent/core/team_manager.py +245 -0
  23. codeagent/core/token_counter.py +41 -0
  24. codeagent/core/tts_voices.py +103 -0
  25. codeagent/core/usage_billing.py +72 -0
  26. codeagent/core/vision_models.py +93 -0
  27. codeagent/memory/diary.py +144 -0
  28. codeagent/persona_defaults/README.md +12 -0
  29. codeagent/persona_defaults/agent.md +352 -0
  30. codeagent/persona_defaults/identity.md +29 -0
  31. codeagent/persona_defaults/memory.md +4 -0
  32. codeagent/persona_defaults/skills.md +325 -0
  33. codeagent/persona_defaults/soul.md +38 -0
  34. codeagent/persona_defaults/tools.md +41 -0
  35. codeagent/persona_defaults/user.md +18 -0
  36. codeagent/runtime/__init__.py +11 -0
  37. codeagent/runtime/agent_context.py +6 -0
  38. codeagent/runtime/agent_runtime.py +21 -0
  39. codeagent/runtime/compact_prompt.py +9 -0
  40. codeagent/runtime/compact_state.py +40 -0
  41. codeagent/runtime/llm_worker.py +132 -0
  42. codeagent/runtime/orchestrator.py +161 -0
  43. codeagent/runtime/prompt_enrichment.py +324 -0
  44. codeagent/runtime/session_manager.py +30 -0
  45. codeagent/runtime/task_split.py +38 -0
  46. codeagent/runtime/turn_loop.py +13 -0
  47. codeagent/runtime/worker.py +48 -0
  48. codeagent/server/__init__.py +505 -0
  49. codeagent/server/app_factory.py +1292 -0
  50. codeagent/server/attachment_api.py +261 -0
  51. codeagent/server/hub.py +175 -0
  52. codeagent/server/icon.png +0 -0
  53. codeagent/server/self_healing.py +143 -0
  54. codeagent/server/team_engine.py +243 -0
  55. codeagent/server/tts_api.py +51 -0
  56. codeagent/server/webui_api_app.py +3180 -0
  57. codeagent/skills/__init__.py +2 -0
  58. codeagent/skills/select.py +144 -0
  59. codeagent/tools/__init__.py +6 -0
  60. codeagent/tools/agent_tools.py +10 -0
  61. codeagent/web/__init__.py +1 -0
  62. codeagent/web/__pycache__/__init__.cpython-313.pyc +0 -0
  63. codeagent/web/__pycache__/app.cpython-313.pyc +0 -0
  64. codeagent/web/__pycache__/auth_impl.cpython-313.pyc +0 -0
  65. codeagent/web/auth_impl.py +326 -0
  66. codeagent/web/static/00-marked.min.js +6 -0
  67. codeagent/web/static/00-mermaid.min.js +2314 -0
  68. codeagent/web/static/00-purify.min.js +3 -0
  69. codeagent/web/static/00-storage.js +83 -0
  70. codeagent/web/static/00-utils.js +51 -0
  71. codeagent/web/static/01-theme.css +96 -0
  72. codeagent/web/static/01a-scroll.js +86 -0
  73. codeagent/web/static/01b-think.js +62 -0
  74. codeagent/web/static/01c-session-identity.js +81 -0
  75. codeagent/web/static/01c-session-thinking.js +61 -0
  76. codeagent/web/static/01c-session-tree-menus.js +349 -0
  77. codeagent/web/static/01c-session-tree.js +531 -0
  78. codeagent/web/static/01c-session-utilities.js +83 -0
  79. codeagent/web/static/01c-vision-model.js +132 -0
  80. codeagent/web/static/01d-image-gen-model.js +84 -0
  81. codeagent/web/static/01e-audio-model.js +97 -0
  82. codeagent/web/static/01f-compose-ui.js +88 -0
  83. codeagent/web/static/01g-tts-settings.js +128 -0
  84. codeagent/web/static/01h-music-model.js +85 -0
  85. codeagent/web/static/01i-model-stack.js +291 -0
  86. codeagent/web/static/01j-video-gen-model.js +85 -0
  87. codeagent/web/static/01k-model-stack-bootstrap.js +66 -0
  88. codeagent/web/static/01k-model-stack-state.js +209 -0
  89. codeagent/web/static/01q-inflight.js +195 -0
  90. codeagent/web/static/02-reset.css +22 -0
  91. codeagent/web/static/02-session-ui.js +201 -0
  92. codeagent/web/static/03-layout-p1.css +2 -0
  93. codeagent/web/static/03-layout-p2.css +2 -0
  94. codeagent/web/static/03a-links-stream.js +88 -0
  95. codeagent/web/static/03b-stream-text.js +119 -0
  96. codeagent/web/static/03c-render-bubble.js +520 -0
  97. codeagent/web/static/03d-agent-bubble.js +126 -0
  98. codeagent/web/static/03e-tool-trace.js +182 -0
  99. codeagent/web/static/03f-timeline.js +54 -0
  100. codeagent/web/static/03g-bubble-tts.js +292 -0
  101. codeagent/web/static/04-components-p1.css +1 -0
  102. codeagent/web/static/04-components-p2b.css +1 -0
  103. codeagent/web/static/04-components-p3.css +2 -0
  104. codeagent/web/static/04-components-p4.css +1 -0
  105. codeagent/web/static/04-components-p5.css +1 -0
  106. codeagent/web/static/04-components-p6.css +58 -0
  107. codeagent/web/static/04-components-p7.css +4 -0
  108. codeagent/web/static/04-components-p8.css +1 -0
  109. codeagent/web/static/04-components-p9.css +1 -0
  110. codeagent/web/static/04-ws-connect.js +351 -0
  111. codeagent/web/static/04-ws-helpers.js +116 -0
  112. codeagent/web/static/05-chat-p1.css +1058 -0
  113. codeagent/web/static/05-chat-p2.css +1 -0
  114. codeagent/web/static/05-chat-p3.css +295 -0
  115. codeagent/web/static/05a-session-history.js +176 -0
  116. codeagent/web/static/05b-session-list.js +114 -0
  117. codeagent/web/static/05c-dialog.js +123 -0
  118. codeagent/web/static/05d-project-create.js +172 -0
  119. codeagent/web/static/05e-project-remote.js +143 -0
  120. codeagent/web/static/06-chat.js +552 -0
  121. codeagent/web/static/06-utilities.css +181 -0
  122. codeagent/web/static/06b-attachments.js +304 -0
  123. codeagent/web/static/06c-camera.js +488 -0
  124. codeagent/web/static/07-activity-bar.css +127 -0
  125. codeagent/web/static/09-git-p1.css +1 -0
  126. codeagent/web/static/09-git-p2.css +1 -0
  127. codeagent/web/static/09a-init-bind.js +110 -0
  128. codeagent/web/static/09b-panel-toggle.js +80 -0
  129. codeagent/web/static/09c-api-refresh.js +100 -0
  130. codeagent/web/static/09d-status-log.js +80 -0
  131. codeagent/web/static/09e-commit.js +80 -0
  132. codeagent/web/static/09f-remote.js +93 -0
  133. codeagent/web/static/11a-cron-parse.js +117 -0
  134. codeagent/web/static/11b-cron-panel.js +100 -0
  135. codeagent/web/static/11c-cron-card.js +133 -0
  136. codeagent/web/static/11d-cron-form.js +105 -0
  137. codeagent/web/static/11e-env-config.js +168 -0
  138. codeagent/web/static/11f-env-llm-a-state.js +136 -0
  139. codeagent/web/static/11f-env-llm-b-form.js +409 -0
  140. codeagent/web/static/11f-env-llm-c-board.js +322 -0
  141. codeagent/web/static/11g-env-paths-git.js +973 -0
  142. codeagent/web/static/11h-env-mcp-a-state.js +161 -0
  143. codeagent/web/static/11h-env-mcp-b-form.js +229 -0
  144. codeagent/web/static/11h-env-mcp-c-board.js +565 -0
  145. codeagent/web/static/12-plugins.js +127 -0
  146. codeagent/web/static/13a-skills.js +156 -0
  147. codeagent/web/static/13a-todo-utils.js +140 -0
  148. codeagent/web/static/13b-todo-fetch.js +106 -0
  149. codeagent/web/static/13b-tools.js +127 -0
  150. codeagent/web/static/13c-todo-crud.js +92 -0
  151. codeagent/web/static/14-activity-bar.js +177 -0
  152. codeagent/web/static/15-plans.css +194 -0
  153. codeagent/web/static/15-plans.js +219 -0
  154. codeagent/web/static/16-mobile.css +612 -0
  155. codeagent/web/static/16-mobile.js +178 -0
  156. codeagent/web/static/17-preset-ux.css +287 -0
  157. codeagent/web/static/18-agent-mgr.css +616 -0
  158. codeagent/web/static/18-agent-mgr.js +204 -0
  159. codeagent/web/static/24-health-dashboard.js +68 -0
  160. codeagent/web/static/99-brand-polish.css +152 -0
  161. codeagent/web/static/body.html +824 -0
  162. codeagent/web/static/setup/setup_form.html +171 -0
  163. codeagent/web/static/setup/setup_head.html +100 -0
  164. codeagent/web/static/setup/setup_tail.html +264 -0
  165. codeagent/web/static/setup/setup_test.html +38 -0
  166. codeagent/web/web_login.html +265 -0
  167. codeagent/web/webui.html +35 -0
  168. tagword_codeagent-1.1.6.dist-info/METADATA +273 -0
  169. tagword_codeagent-1.1.6.dist-info/RECORD +173 -0
  170. tagword_codeagent-1.1.6.dist-info/WHEEL +5 -0
  171. tagword_codeagent-1.1.6.dist-info/entry_points.txt +3 -0
  172. tagword_codeagent-1.1.6.dist-info/licenses/LICENSE +21 -0
  173. tagword_codeagent-1.1.6.dist-info/top_level.txt +1 -0
@@ -0,0 +1,171 @@
1
+ color: var(--c-text);
2
+ }
3
+ input, select {
4
+ width: 100%;
5
+ padding: 0.5rem 0.65rem;
6
+ border-radius: 7px;
7
+ border: 1px solid var(--c-border);
8
+ background: var(--c-bg);
9
+ color: var(--c-text);
10
+ font-size: 0.92rem;
11
+ outline: none;
12
+ transition: border-color 0.15s;
13
+ }
14
+ input:focus, select:focus {
15
+ border-color: var(--c-primary);
16
+ box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
17
+ }
18
+ .actions {
19
+ display: flex;
20
+ gap: 0.6rem;
21
+ flex-wrap: wrap;
22
+ margin-top: 1rem;
23
+ }
24
+ button {
25
+ padding: 0.5rem 1.1rem;
26
+ border-radius: 8px;
27
+ border: 1px solid var(--c-border);
28
+ background: var(--c-bg);
29
+ color: var(--c-text);
30
+ font-size: 0.9rem;
31
+ cursor: pointer;
32
+ transition: all 0.12s;
33
+ font-weight: 500;
34
+ }
35
+ button:hover { opacity: 0.85; }
36
+ button:disabled { opacity: 0.4; cursor: not-allowed; }
37
+ .btn-primary {
38
+ background: var(--c-primary);
39
+ color: #fff;
40
+ border-color: var(--c-primary);
41
+ }
42
+ .btn-primary:hover { background: var(--c-primary-hover); }
43
+ .btn-primary:disabled { background: var(--c-muted); border-color: var(--c-muted); }
44
+ .msg { font-size: 0.88rem; min-height: 1.3rem; margin-top: 0.5rem; }
45
+ .msg.err { color: var(--c-err); }
46
+ .msg.ok { color: var(--c-ok); }
47
+ .token-display {
48
+ display: flex;
49
+ gap: 0.5rem;
50
+ align-items: center;
51
+ margin-top: 0.5rem;
52
+ }
53
+ .token-display input { flex: 1; font-family: monospace; }
54
+ .hint {
55
+ font-size: 0.85rem;
56
+ color: var(--c-muted);
57
+ margin: 0.5rem 0;
58
+ }
59
+ code {
60
+ font-size: 0.9em;
61
+ padding: 0.1em 0.3em;
62
+ background: var(--c-border);
63
+ border-radius: 4px;
64
+ }
65
+ .setup-hero {
66
+ display: flex;
67
+ align-items: flex-start;
68
+ gap: 1rem;
69
+ margin-bottom: 1.5rem;
70
+ padding: 1.1rem 1.2rem;
71
+ border-radius: 14px;
72
+ background: linear-gradient(135deg, rgba(37, 99, 235, 0.09) 0%, rgba(99, 102, 241, 0.06) 100%);
73
+ border: 1px solid rgba(37, 99, 235, 0.2);
74
+ }
75
+ @media (prefers-color-scheme: dark) {
76
+ .setup-hero {
77
+ background: linear-gradient(135deg, rgba(59, 130, 246, 0.14) 0%, rgba(79, 70, 229, 0.09) 100%);
78
+ border-color: rgba(96, 165, 250, 0.25);
79
+ }
80
+ }
81
+ .setup-hero__icon {
82
+ width: 52px;
83
+ height: 52px;
84
+ border-radius: 14px;
85
+ object-fit: contain;
86
+ flex-shrink: 0;
87
+ box-shadow: 0 2px 14px rgba(37, 99, 235, 0.22), 0 0 0 1px rgba(255,255,255,0.06);
88
+ background: #fff;
89
+ padding: 4px;
90
+ }
91
+ .setup-hero__text h1 {
92
+ margin: 0 0 0.35rem 0;
93
+ font-size: 1.35rem;
94
+ font-weight: 650;
95
+ letter-spacing: -0.02em;
96
+ }
97
+ .setup-hero .subtitle {
98
+ margin: 0;
99
+ }
100
+ .field-advanced {
101
+ margin-top: 0.75rem;
102
+ padding: 0.75rem;
103
+ border-radius: 8px;
104
+ border: 1px dashed var(--c-border);
105
+ background: rgba(127, 127, 127, 0.06);
106
+ }
107
+ .field-advanced[hidden] { display: none !important; }
108
+ .check-row {
109
+ display: flex;
110
+ align-items: center;
111
+ gap: 0.45rem;
112
+ font-size: 0.88rem;
113
+ margin: 0.35rem 0 0.6rem;
114
+ }
115
+ .check-row input { width: auto; }
116
+ </style>
117
+ </head>
118
+ <body>
119
+ <div class="setup-hero">
120
+ <img class="setup-hero__icon" src="/icon.png" alt="" width="52" height="52" decoding="async"/>
121
+ <div class="setup-hero__text">
122
+ <h1>初始化</h1>
123
+ <p class="subtitle">添加主对话模型并生成访问 Token。</p>
124
+ </div>
125
+ </div>
126
+
127
+ <div class="card active" id="step1">
128
+ <div class="card-body">
129
+ <div class="card-title">
130
+ <span class="step-badge">1</span>
131
+ 对话模型
132
+ </div>
133
+ <div class="field-row">
134
+ <div>
135
+ <label for="fProvider">服务商</label>
136
+ <select id="fProvider"></select>
137
+ </div>
138
+ <div>
139
+ <label for="fModel">模型</label>
140
+ <select id="fModel"></select>
141
+ </div>
142
+ </div>
143
+ <div class="field-row">
144
+ <div>
145
+ <label for="fKey">API Key</label>
146
+ <input id="fKey" type="password" placeholder="sk-... 本地 Ollama 等可留空"/>
147
+ </div>
148
+ </div>
149
+ <label class="check-row">
150
+ <input type="checkbox" id="chkAdvanced"/>
151
+ <span>自定义 Base URL</span>
152
+ </label>
153
+ <div class="field-advanced" id="advancedBox" hidden>
154
+ <div class="field-row">
155
+ <div>
156
+ <label for="fBase">Base URL</label>
157
+ <input id="fBase" placeholder="https://api.example.com/v1"/>
158
+ </div>
159
+ <div>
160
+ <label for="fModelCustom">自定义模型 ID</label>
161
+ <input id="fModelCustom" placeholder="模型 ID(覆盖上方下拉)"/>
162
+ </div>
163
+ </div>
164
+ </div>
165
+ <div class="actions">
166
+ <button id="btnTest" type="button">测试连接</button>
167
+ <button id="btnSave" type="button" class="btn-primary">保存并继续 →</button>
168
+ </div>
169
+ <div id="msg1" class="msg"></div>
170
+ </div>
171
+ </div>
@@ -0,0 +1,100 @@
1
+ <!DOCTYPE html>
2
+ <html lang="zh-CN">
3
+ <head>
4
+ <meta charset="utf-8"/>
5
+ <meta name="viewport" content="width=device-width, initial-scale=1"/>
6
+ <link rel="icon" type="image/png" href="/icon.png"/>
7
+ <title>CodeAgent · 初始化</title>
8
+ <style>
9
+ :root {
10
+ color-scheme: light dark;
11
+ --c-bg: #fff;
12
+ --c-text: #1a1a2e;
13
+ --c-border: #d0d5dd;
14
+ --c-muted: #667085;
15
+ --c-card-bg: #f9fafb;
16
+ --c-primary: #2563eb;
17
+ --c-primary-hover: #1d4ed8;
18
+ --c-err: #dc2626;
19
+ --c-ok: #16a34a;
20
+ --radius: 10px;
21
+ --sp: 1rem;
22
+ }
23
+ @media (prefers-color-scheme: dark) {
24
+ :root {
25
+ --c-bg: #0f172a;
26
+ --c-text: #e2e8f0;
27
+ --c-border: #334155;
28
+ --c-muted: #94a3b8;
29
+ --c-card-bg: #1e293b;
30
+ --c-primary: #3b82f6;
31
+ --c-primary-hover: #2563eb;
32
+ }
33
+ }
34
+ * { box-sizing: border-box; }
35
+ body {
36
+ font-family: system-ui, -apple-system, sans-serif;
37
+ background: var(--c-bg);
38
+ color: var(--c-text);
39
+ max-width: 720px;
40
+ margin: 2rem auto;
41
+ padding: 0 1rem 3rem;
42
+ line-height: 1.6;
43
+ }
44
+ h1 {
45
+ font-size: 1.35rem;
46
+ font-weight: 600;
47
+ margin: 0 0 0.2rem 0;
48
+ }
49
+ .subtitle {
50
+ color: var(--c-muted);
51
+ font-size: 0.92rem;
52
+ margin: 0 0 1.5rem 0;
53
+ }
54
+ .card { display: none; }
55
+ .card.active { display: block; }
56
+ .card-body {
57
+ border: 1px solid var(--c-border);
58
+ border-radius: var(--radius);
59
+ padding: 1.25rem;
60
+ background: var(--c-card-bg);
61
+ margin-top: 0.5rem;
62
+ }
63
+ .card-title {
64
+ font-size: 1.05rem;
65
+ font-weight: 600;
66
+ margin: 0 0 0.25rem 0;
67
+ display: flex;
68
+ align-items: center;
69
+ gap: 0.5rem;
70
+ }
71
+ .card-title .step-badge {
72
+ display: inline-flex;
73
+ align-items: center;
74
+ justify-content: center;
75
+ width: 24px;
76
+ height: 24px;
77
+ border-radius: 50%;
78
+ background: var(--c-primary);
79
+ color: #fff;
80
+ font-size: 0.8rem;
81
+ font-weight: 700;
82
+ flex-shrink: 0;
83
+ }
84
+ .card-desc {
85
+ color: var(--c-muted);
86
+ font-size: 0.88rem;
87
+ margin: 0 0 1rem 0;
88
+ }
89
+ .field-row {
90
+ display: flex;
91
+ gap: 0.75rem;
92
+ flex-wrap: wrap;
93
+ margin-bottom: 0.6rem;
94
+ }
95
+ .field-row > * { flex: 1; min-width: 200px; }
96
+ label {
97
+ display: block;
98
+ font-size: 0.85rem;
99
+ font-weight: 500;
100
+ margin-bottom: 0.25rem;
@@ -0,0 +1,264 @@
1
+ <script>
2
+ const $ = (id) => document.getElementById(id);
3
+
4
+ function setMsg(id, text, isErr) {
5
+ const el = $(id);
6
+ if (!el) return;
7
+ el.textContent = text || '';
8
+ el.className = 'msg' + (isErr ? ' err' : text && !isErr ? ' ok' : '');
9
+ }
10
+
11
+ async function postJson(url, body) {
12
+ const r = await fetch(url, {
13
+ method: 'POST',
14
+ headers: { 'Content-Type': 'application/json' },
15
+ credentials: 'same-origin',
16
+ body: JSON.stringify(body || {})
17
+ });
18
+ const j = await r.json().catch(() => ({}));
19
+ if (!r.ok) throw new Error(j.detail || r.statusText);
20
+ return j;
21
+ }
22
+
23
+ let providerCatalog = [];
24
+ const SELF_HOSTED = ['ollama', 'openai_compatible', 'sglang', 'custom'];
25
+
26
+ const FALLBACK_PROVIDERS = [
27
+ {
28
+ id: 'deepseek',
29
+ label: 'DeepSeek',
30
+ capabilities: ['chat'],
31
+ requires_api_key: true,
32
+ default_base_url: 'https://api.deepseek.com/v1',
33
+ models: { chat: [
34
+ { id: 'deepseek-v4-flash', label: 'deepseek-v4-flash' },
35
+ { id: 'deepseek-v4-pro', label: 'deepseek-v4-pro' },
36
+ ]},
37
+ },
38
+ {
39
+ id: 'openai_compatible',
40
+ label: 'OpenAI 兼容',
41
+ capabilities: ['chat'],
42
+ requires_api_key: true,
43
+ default_base_url: '',
44
+ models: { chat: [] },
45
+ },
46
+ {
47
+ id: 'ollama',
48
+ label: 'Ollama',
49
+ capabilities: ['chat'],
50
+ requires_api_key: false,
51
+ default_base_url: 'http://127.0.0.1:11434/v1',
52
+ models: { chat: [] },
53
+ },
54
+ ];
55
+
56
+ function providerNeedsKey(pid) {
57
+ const p = providerCatalog.find(function(x) { return x.id === pid; });
58
+ return p ? !!p.requires_api_key : true;
59
+ }
60
+
61
+ function listChatModels(providerId) {
62
+ const p = providerCatalog.find(function(x) { return x.id === providerId; });
63
+ if (!p || !p.models || !p.models.chat) return [];
64
+ return p.models.chat;
65
+ }
66
+
67
+ function fillProviderSelect() {
68
+ const sel = $('fProvider');
69
+ if (!sel) return;
70
+ sel.innerHTML = '';
71
+ const chatProviders = providerCatalog.filter(function(p) {
72
+ return (p.capabilities || []).indexOf('chat') >= 0;
73
+ });
74
+ chatProviders.forEach(function(p) {
75
+ const o = document.createElement('option');
76
+ o.value = p.id;
77
+ o.textContent = p.label || p.id;
78
+ sel.appendChild(o);
79
+ });
80
+ if (!chatProviders.length) {
81
+ const o = document.createElement('option');
82
+ o.value = 'openai_compatible';
83
+ o.textContent = 'OpenAI 兼容';
84
+ sel.appendChild(o);
85
+ }
86
+ }
87
+
88
+ function fillModelSelect() {
89
+ const prov = $('fProvider').value;
90
+ const sel = $('fModel');
91
+ sel.innerHTML = '';
92
+ const models = listChatModels(prov);
93
+ if (models.length) {
94
+ models.forEach(function(m) {
95
+ const o = document.createElement('option');
96
+ o.value = m.id;
97
+ o.textContent = m.label || m.id;
98
+ sel.appendChild(o);
99
+ });
100
+ sel.disabled = false;
101
+ } else {
102
+ const o = document.createElement('option');
103
+ o.value = '';
104
+ o.textContent = '请在高级模式填写模型 ID';
105
+ sel.appendChild(o);
106
+ sel.disabled = true;
107
+ }
108
+ const p = providerCatalog.find(function(x) { return x.id === prov; });
109
+ if (p && p.default_base_url && $('fBase')) {
110
+ $('fBase').placeholder = p.default_base_url;
111
+ if (!$('fBase').value.trim()) $('fBase').value = p.default_base_url;
112
+ }
113
+ const needAdv = SELF_HOSTED.indexOf(prov) >= 0 || !models.length;
114
+ if ($('chkAdvanced')) {
115
+ $('chkAdvanced').checked = needAdv;
116
+ toggleAdvanced();
117
+ }
118
+ }
119
+
120
+ function toggleAdvanced() {
121
+ const on = $('chkAdvanced') && $('chkAdvanced').checked;
122
+ if ($('advancedBox')) $('advancedBox').hidden = !on;
123
+ }
124
+
125
+ function collectPresetPayload() {
126
+ const provider = $('fProvider').value.trim();
127
+ const modelSel = $('fModel').value.trim();
128
+ const modelCustom = ($('fModelCustom') && $('fModelCustom').value.trim()) || '';
129
+ const model = modelCustom || modelSel;
130
+ const key = $('fKey').value.trim();
131
+ const advanced = $('chkAdvanced') && $('chkAdvanced').checked;
132
+ const base = $('fBase').value.trim();
133
+ if (!provider) throw new Error('请选择服务商');
134
+ if (!model) throw new Error('请选择或填写模型');
135
+ if (providerNeedsKey(provider) && !key) throw new Error('该服务商需要 API Key');
136
+ const payload = {
137
+ provider: provider,
138
+ use_type: 'chat',
139
+ model: model,
140
+ api_key: key,
141
+ };
142
+ if (advanced || SELF_HOSTED.indexOf(provider) >= 0) {
143
+ payload.advanced = true;
144
+ if (base) payload.base_url = base;
145
+ }
146
+ return payload;
147
+ }
148
+
149
+ async function loadProviders() {
150
+ try {
151
+ const r = await fetch('/api/ui/llm/providers', { credentials: 'same-origin' });
152
+ if (r.ok) {
153
+ const j = await r.json();
154
+ providerCatalog = j.providers || [];
155
+ }
156
+ } catch (_) {}
157
+ if (!providerCatalog.length) providerCatalog = FALLBACK_PROVIDERS.slice();
158
+ fillProviderSelect();
159
+ fillModelSelect();
160
+ if (!$('fProvider').options.length) {
161
+ setMsg('msg1', '无法加载服务商列表', true);
162
+ }
163
+ }
164
+
165
+ document.addEventListener('DOMContentLoaded', function() {
166
+ $('fProvider') && $('fProvider').addEventListener('change', fillModelSelect);
167
+ $('chkAdvanced') && $('chkAdvanced').addEventListener('change', toggleAdvanced);
168
+ loadProviders();
169
+ });
170
+
171
+ // --- Step 1: save chat preset ---
172
+
173
+ $('btnTest').onclick = async () => {
174
+ setMsg('msg1', '测试连接中…');
175
+ try {
176
+ const payload = collectPresetPayload();
177
+ const j = await postJson('/api/ui/llm/presets/test', payload);
178
+ setMsg('msg1', '连接成功:' + (j.model_hint || payload.model || 'OK'));
179
+ } catch (e) {
180
+ setMsg('msg1', String(e.message || e), true);
181
+ }
182
+ };
183
+
184
+ $('btnSave').onclick = async () => {
185
+ setMsg('msg1', '保存中…');
186
+ try {
187
+ const payload = collectPresetPayload();
188
+ const saved = await postJson('/api/ui/llm/presets', payload);
189
+ const pid = saved.preset_id || payload.id;
190
+ if (!pid) throw new Error('保存成功但未返回 preset_id');
191
+ await postJson('/api/ui/llm/presets/default', { preset_id: pid, use_type: 'chat' });
192
+ setMsg('msg1', '主模型已保存并设为默认。');
193
+ document.querySelector('.card.active').classList.remove('active');
194
+ $('step2').classList.add('active');
195
+ setMsg('msg2', '');
196
+ } catch (e) {
197
+ setMsg('msg1', String(e.message || e), true);
198
+ }
199
+ };
200
+
201
+ // --- Step 2: token + env defaults (via finish) ---
202
+
203
+ let lastToken = '';
204
+
205
+ $('btnFinish').onclick = async () => {
206
+ setMsg('msg2', '生成中…');
207
+ try {
208
+ const j = await postJson('/api/ui/setup/finish', {});
209
+ lastToken = String(j.webui_token || '').trim();
210
+ if (!lastToken) throw new Error('未返回 Token');
211
+ $('tokenVal').value = lastToken;
212
+ $('tokenBox').hidden = false;
213
+ $('btnCopyToken').disabled = false;
214
+ $('tokenHint').hidden = false;
215
+ $('btnFinish').disabled = true;
216
+ $('btnContinue').hidden = false;
217
+ $('btnContinue').disabled = false;
218
+ setMsg('msg2', 'Token 已生成,请先复制保存。');
219
+ } catch (e) {
220
+ setMsg('msg2', String(e.message || e), true);
221
+ }
222
+ };
223
+
224
+ $('btnContinue').onclick = () => {
225
+ document.querySelector('.card.active').classList.remove('active');
226
+ $('step3').classList.add('active');
227
+ $('btnStart').disabled = !lastToken;
228
+ setMsg('msg3', '');
229
+ };
230
+
231
+ $('btnCopyToken').onclick = async () => {
232
+ const t = String($('tokenVal').value || '').trim();
233
+ if (!t) return;
234
+ try {
235
+ await navigator.clipboard.writeText(t);
236
+ setMsg('msg2', '已复制 Token。请妥善保存!');
237
+ } catch (e) {
238
+ setMsg('msg2', '复制失败,请手动选中复制。', true);
239
+ }
240
+ };
241
+
242
+ // --- Step 3: enter app ---
243
+
244
+ $('btnStart').onclick = async () => {
245
+ if (!lastToken) return;
246
+ try {
247
+ setMsg('msg3', '完成初始化…');
248
+ await postJson('/api/ui/setup/complete', {});
249
+ setMsg('msg3', '登录中…');
250
+ const r = await postJson('/api/ui/auth', { token: lastToken });
251
+ if (r.ws_query_token) {
252
+ try { sessionStorage.setItem('oa_webui_ws_token', r.ws_query_token); } catch (_) {}
253
+ } else {
254
+ try { sessionStorage.removeItem('oa_webui_ws_token'); } catch (_) {}
255
+ }
256
+ } catch (e) {
257
+ setMsg('msg3', String(e.message || e), true);
258
+ return;
259
+ }
260
+ location.href = '/?setup_done=1';
261
+ };
262
+ </script>
263
+ </body>
264
+ </html>
@@ -0,0 +1,38 @@
1
+
2
+ <!-- Step 2: Security Token -->
3
+ <div class="card" id="step2">
4
+ <div class="card-body">
5
+ <div class="card-title">
6
+ <span class="step-badge">2</span>
7
+ 访问 Token
8
+ </div>
9
+ <p class="card-desc">生成后请复制保存,再进入下一步。</p>
10
+ <div class="actions">
11
+ <button id="btnFinish" type="button" class="btn-primary">生成 Token</button>
12
+ <button id="btnContinue" type="button" class="btn-primary" disabled hidden>已复制,继续 →</button>
13
+ </div>
14
+ <div class="token-display" id="tokenBox" hidden>
15
+ <input id="tokenVal" readonly placeholder="Token 将显示在这里"/>
16
+ <button id="btnCopyToken" type="button" disabled>复制</button>
17
+ </div>
18
+ <div id="msg2" class="msg"></div>
19
+ <p class="hint" id="tokenHint" hidden>
20
+ 请复制并妥善保存 Token,丢失后需通过 CLI 重置。确认保存后再点「已复制,继续」。
21
+ </p>
22
+ </div>
23
+ </div>
24
+
25
+ <!-- Step 3: Done + Start -->
26
+ <div class="card" id="step3">
27
+ <div class="card-body">
28
+ <div class="card-title">
29
+ <span class="step-badge">3</span>
30
+ 完成
31
+ </div>
32
+ <p class="card-desc">确认 Token 已保存后,进入主界面开始对话。</p>
33
+ <div class="actions">
34
+ <button id="btnStart" type="button" class="btn-primary" disabled>开始对话 →</button>
35
+ </div>
36
+ <div id="msg3" class="msg"></div>
37
+ </div>
38
+ </div>