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.
- codeagent/__init__.py +10 -0
- codeagent/__main__.py +13 -0
- codeagent/cli/__init__.py +13 -0
- codeagent/cli/entrypoint.py +161 -0
- codeagent/cli/main.py +979 -0
- codeagent/core/__init__.py +2 -0
- codeagent/core/attachments.py +342 -0
- codeagent/core/audio_models.py +50 -0
- codeagent/core/bootstrap.py +178 -0
- codeagent/core/default_presets.py +159 -0
- codeagent/core/env.py +106 -0
- codeagent/core/folder_picker.py +151 -0
- codeagent/core/image_understanding.py +90 -0
- codeagent/core/models.py +6 -0
- codeagent/core/paths.py +238 -0
- codeagent/core/pricing.py +107 -0
- codeagent/core/process_ports.py +258 -0
- codeagent/core/seed_bridge.py +21 -0
- codeagent/core/settings.py +98 -0
- codeagent/core/speech_synth.py +330 -0
- codeagent/core/team_config.py +247 -0
- codeagent/core/team_manager.py +245 -0
- codeagent/core/token_counter.py +41 -0
- codeagent/core/tts_voices.py +103 -0
- codeagent/core/usage_billing.py +72 -0
- codeagent/core/vision_models.py +93 -0
- codeagent/memory/diary.py +144 -0
- codeagent/persona_defaults/README.md +12 -0
- codeagent/persona_defaults/agent.md +352 -0
- codeagent/persona_defaults/identity.md +29 -0
- codeagent/persona_defaults/memory.md +4 -0
- codeagent/persona_defaults/skills.md +325 -0
- codeagent/persona_defaults/soul.md +38 -0
- codeagent/persona_defaults/tools.md +41 -0
- codeagent/persona_defaults/user.md +18 -0
- codeagent/runtime/__init__.py +11 -0
- codeagent/runtime/agent_context.py +6 -0
- codeagent/runtime/agent_runtime.py +21 -0
- codeagent/runtime/compact_prompt.py +9 -0
- codeagent/runtime/compact_state.py +40 -0
- codeagent/runtime/llm_worker.py +132 -0
- codeagent/runtime/orchestrator.py +161 -0
- codeagent/runtime/prompt_enrichment.py +324 -0
- codeagent/runtime/session_manager.py +30 -0
- codeagent/runtime/task_split.py +38 -0
- codeagent/runtime/turn_loop.py +13 -0
- codeagent/runtime/worker.py +48 -0
- codeagent/server/__init__.py +505 -0
- codeagent/server/app_factory.py +1292 -0
- codeagent/server/attachment_api.py +261 -0
- codeagent/server/hub.py +175 -0
- codeagent/server/icon.png +0 -0
- codeagent/server/self_healing.py +143 -0
- codeagent/server/team_engine.py +243 -0
- codeagent/server/tts_api.py +51 -0
- codeagent/server/webui_api_app.py +3180 -0
- codeagent/skills/__init__.py +2 -0
- codeagent/skills/select.py +144 -0
- codeagent/tools/__init__.py +6 -0
- codeagent/tools/agent_tools.py +10 -0
- codeagent/web/__init__.py +1 -0
- codeagent/web/__pycache__/__init__.cpython-313.pyc +0 -0
- codeagent/web/__pycache__/app.cpython-313.pyc +0 -0
- codeagent/web/__pycache__/auth_impl.cpython-313.pyc +0 -0
- codeagent/web/auth_impl.py +326 -0
- codeagent/web/static/00-marked.min.js +6 -0
- codeagent/web/static/00-mermaid.min.js +2314 -0
- codeagent/web/static/00-purify.min.js +3 -0
- codeagent/web/static/00-storage.js +83 -0
- codeagent/web/static/00-utils.js +51 -0
- codeagent/web/static/01-theme.css +96 -0
- codeagent/web/static/01a-scroll.js +86 -0
- codeagent/web/static/01b-think.js +62 -0
- codeagent/web/static/01c-session-identity.js +81 -0
- codeagent/web/static/01c-session-thinking.js +61 -0
- codeagent/web/static/01c-session-tree-menus.js +349 -0
- codeagent/web/static/01c-session-tree.js +531 -0
- codeagent/web/static/01c-session-utilities.js +83 -0
- codeagent/web/static/01c-vision-model.js +132 -0
- codeagent/web/static/01d-image-gen-model.js +84 -0
- codeagent/web/static/01e-audio-model.js +97 -0
- codeagent/web/static/01f-compose-ui.js +88 -0
- codeagent/web/static/01g-tts-settings.js +128 -0
- codeagent/web/static/01h-music-model.js +85 -0
- codeagent/web/static/01i-model-stack.js +291 -0
- codeagent/web/static/01j-video-gen-model.js +85 -0
- codeagent/web/static/01k-model-stack-bootstrap.js +66 -0
- codeagent/web/static/01k-model-stack-state.js +209 -0
- codeagent/web/static/01q-inflight.js +195 -0
- codeagent/web/static/02-reset.css +22 -0
- codeagent/web/static/02-session-ui.js +201 -0
- codeagent/web/static/03-layout-p1.css +2 -0
- codeagent/web/static/03-layout-p2.css +2 -0
- codeagent/web/static/03a-links-stream.js +88 -0
- codeagent/web/static/03b-stream-text.js +119 -0
- codeagent/web/static/03c-render-bubble.js +520 -0
- codeagent/web/static/03d-agent-bubble.js +126 -0
- codeagent/web/static/03e-tool-trace.js +182 -0
- codeagent/web/static/03f-timeline.js +54 -0
- codeagent/web/static/03g-bubble-tts.js +292 -0
- codeagent/web/static/04-components-p1.css +1 -0
- codeagent/web/static/04-components-p2b.css +1 -0
- codeagent/web/static/04-components-p3.css +2 -0
- codeagent/web/static/04-components-p4.css +1 -0
- codeagent/web/static/04-components-p5.css +1 -0
- codeagent/web/static/04-components-p6.css +58 -0
- codeagent/web/static/04-components-p7.css +4 -0
- codeagent/web/static/04-components-p8.css +1 -0
- codeagent/web/static/04-components-p9.css +1 -0
- codeagent/web/static/04-ws-connect.js +351 -0
- codeagent/web/static/04-ws-helpers.js +116 -0
- codeagent/web/static/05-chat-p1.css +1058 -0
- codeagent/web/static/05-chat-p2.css +1 -0
- codeagent/web/static/05-chat-p3.css +295 -0
- codeagent/web/static/05a-session-history.js +176 -0
- codeagent/web/static/05b-session-list.js +114 -0
- codeagent/web/static/05c-dialog.js +123 -0
- codeagent/web/static/05d-project-create.js +172 -0
- codeagent/web/static/05e-project-remote.js +143 -0
- codeagent/web/static/06-chat.js +552 -0
- codeagent/web/static/06-utilities.css +181 -0
- codeagent/web/static/06b-attachments.js +304 -0
- codeagent/web/static/06c-camera.js +488 -0
- codeagent/web/static/07-activity-bar.css +127 -0
- codeagent/web/static/09-git-p1.css +1 -0
- codeagent/web/static/09-git-p2.css +1 -0
- codeagent/web/static/09a-init-bind.js +110 -0
- codeagent/web/static/09b-panel-toggle.js +80 -0
- codeagent/web/static/09c-api-refresh.js +100 -0
- codeagent/web/static/09d-status-log.js +80 -0
- codeagent/web/static/09e-commit.js +80 -0
- codeagent/web/static/09f-remote.js +93 -0
- codeagent/web/static/11a-cron-parse.js +117 -0
- codeagent/web/static/11b-cron-panel.js +100 -0
- codeagent/web/static/11c-cron-card.js +133 -0
- codeagent/web/static/11d-cron-form.js +105 -0
- codeagent/web/static/11e-env-config.js +168 -0
- codeagent/web/static/11f-env-llm-a-state.js +136 -0
- codeagent/web/static/11f-env-llm-b-form.js +409 -0
- codeagent/web/static/11f-env-llm-c-board.js +322 -0
- codeagent/web/static/11g-env-paths-git.js +973 -0
- codeagent/web/static/11h-env-mcp-a-state.js +161 -0
- codeagent/web/static/11h-env-mcp-b-form.js +229 -0
- codeagent/web/static/11h-env-mcp-c-board.js +565 -0
- codeagent/web/static/12-plugins.js +127 -0
- codeagent/web/static/13a-skills.js +156 -0
- codeagent/web/static/13a-todo-utils.js +140 -0
- codeagent/web/static/13b-todo-fetch.js +106 -0
- codeagent/web/static/13b-tools.js +127 -0
- codeagent/web/static/13c-todo-crud.js +92 -0
- codeagent/web/static/14-activity-bar.js +177 -0
- codeagent/web/static/15-plans.css +194 -0
- codeagent/web/static/15-plans.js +219 -0
- codeagent/web/static/16-mobile.css +612 -0
- codeagent/web/static/16-mobile.js +178 -0
- codeagent/web/static/17-preset-ux.css +287 -0
- codeagent/web/static/18-agent-mgr.css +616 -0
- codeagent/web/static/18-agent-mgr.js +204 -0
- codeagent/web/static/24-health-dashboard.js +68 -0
- codeagent/web/static/99-brand-polish.css +152 -0
- codeagent/web/static/body.html +824 -0
- codeagent/web/static/setup/setup_form.html +171 -0
- codeagent/web/static/setup/setup_head.html +100 -0
- codeagent/web/static/setup/setup_tail.html +264 -0
- codeagent/web/static/setup/setup_test.html +38 -0
- codeagent/web/web_login.html +265 -0
- codeagent/web/webui.html +35 -0
- tagword_codeagent-1.1.6.dist-info/METADATA +273 -0
- tagword_codeagent-1.1.6.dist-info/RECORD +173 -0
- tagword_codeagent-1.1.6.dist-info/WHEEL +5 -0
- tagword_codeagent-1.1.6.dist-info/entry_points.txt +3 -0
- tagword_codeagent-1.1.6.dist-info/licenses/LICENSE +21 -0
- tagword_codeagent-1.1.6.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
/* ================================================================
|
|
2
|
+
* 06-animations.css — Running states, animations, responsive
|
|
3
|
+
* ================================================================ */
|
|
4
|
+
|
|
5
|
+
/* Session list running state */
|
|
6
|
+
.sess-row.is-running { position: relative; }
|
|
7
|
+
.sess-row.is-running::after {
|
|
8
|
+
content: '';
|
|
9
|
+
position: absolute;
|
|
10
|
+
left: 0;
|
|
11
|
+
top: 6px;
|
|
12
|
+
bottom: 6px;
|
|
13
|
+
width: 3px;
|
|
14
|
+
border-radius: 3px;
|
|
15
|
+
background: var(--accent, #4f46e5);
|
|
16
|
+
box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent, #4f46e5) 55%, transparent);
|
|
17
|
+
animation: oa-pulse-bar 1.4s ease-in-out infinite;
|
|
18
|
+
pointer-events: none;
|
|
19
|
+
}
|
|
20
|
+
.sess-row.is-running .sess-item__title::after {
|
|
21
|
+
content: '';
|
|
22
|
+
display: inline-block;
|
|
23
|
+
width: 7px;
|
|
24
|
+
height: 7px;
|
|
25
|
+
margin-left: 6px;
|
|
26
|
+
border-radius: 50%;
|
|
27
|
+
background: var(--accent, #4f46e5);
|
|
28
|
+
vertical-align: middle;
|
|
29
|
+
animation: oa-pulse 1.15s ease-in-out infinite;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/* Global progress bar */
|
|
33
|
+
.oa-global-progress {
|
|
34
|
+
position: absolute;
|
|
35
|
+
left: 0; right: 0;
|
|
36
|
+
top: 100%;
|
|
37
|
+
height: 2px;
|
|
38
|
+
overflow: hidden;
|
|
39
|
+
pointer-events: none;
|
|
40
|
+
opacity: 0;
|
|
41
|
+
transition: opacity 0.2s ease;
|
|
42
|
+
z-index: 5;
|
|
43
|
+
}
|
|
44
|
+
.oa-global-progress::before {
|
|
45
|
+
content: '';
|
|
46
|
+
position: absolute;
|
|
47
|
+
top: 0;
|
|
48
|
+
left: -40%;
|
|
49
|
+
width: 40%;
|
|
50
|
+
height: 100%;
|
|
51
|
+
background: linear-gradient(90deg, transparent, var(--accent, #4f46e5) 50%, transparent);
|
|
52
|
+
animation: oa-progress-slide 1.4s ease-in-out infinite;
|
|
53
|
+
}
|
|
54
|
+
body.chat-running .oa-global-progress { opacity: 1; }
|
|
55
|
+
|
|
56
|
+
/* Keyframes */
|
|
57
|
+
@keyframes oa-pulse {
|
|
58
|
+
0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent, #4f46e5) 55%, transparent); transform: scale(1); }
|
|
59
|
+
70% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--accent, #4f46e5) 0%, transparent); transform: scale(1.05); }
|
|
60
|
+
100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent, #4f46e5) 0%, transparent); transform: scale(1); }
|
|
61
|
+
}
|
|
62
|
+
@keyframes oa-pulse-bar {
|
|
63
|
+
0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent, #4f46e5) 55%, transparent); }
|
|
64
|
+
70% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent, #4f46e5) 0%, transparent); }
|
|
65
|
+
100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent, #4f46e5) 0%, transparent); }
|
|
66
|
+
}
|
|
67
|
+
@keyframes oa-shimmer {
|
|
68
|
+
0% { background-position: 200% 0; }
|
|
69
|
+
100% { background-position: -200% 0; }
|
|
70
|
+
}
|
|
71
|
+
@keyframes oa-progress-slide {
|
|
72
|
+
0% { left: -40%; }
|
|
73
|
+
100% { left: 100%; }
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.sess-row.is-completed::after,
|
|
77
|
+
.sess-row.is-completed .sess-item__title::after {
|
|
78
|
+
display: none;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@media (prefers-reduced-motion: reduce) {
|
|
82
|
+
details.oa-live-tool.is-running > summary,
|
|
83
|
+
details.oa-live-tool.is-running .oa-live-tool-spinner,
|
|
84
|
+
.sess-row.is-running::after,
|
|
85
|
+
.sess-row.is-running .sess-item__title::after,
|
|
86
|
+
.oa-global-progress::before { animation: none; }
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/* ============ Todo Panel ============ */
|
|
90
|
+
|
|
91
|
+
.todo-panel {
|
|
92
|
+
width: 280px;
|
|
93
|
+
flex-shrink: 0;
|
|
94
|
+
border-left: 1px solid var(--border);
|
|
95
|
+
background: var(--bg-panel);
|
|
96
|
+
display: none;
|
|
97
|
+
flex-direction: column;
|
|
98
|
+
min-height: 0;
|
|
99
|
+
}
|
|
100
|
+
.todo-panel__header {
|
|
101
|
+
padding: var(--sp-3) var(--sp-4);
|
|
102
|
+
font-size: 10.5px;
|
|
103
|
+
font-weight: 600;
|
|
104
|
+
text-transform: uppercase;
|
|
105
|
+
letter-spacing: 0.07em;
|
|
106
|
+
color: var(--text-muted);
|
|
107
|
+
border-bottom: 1px solid var(--border);
|
|
108
|
+
flex-shrink: 0;
|
|
109
|
+
}
|
|
110
|
+
.todo-panel__list {
|
|
111
|
+
flex: 1;
|
|
112
|
+
min-height: 0;
|
|
113
|
+
overflow-y: auto;
|
|
114
|
+
padding: var(--sp-1) var(--sp-2);
|
|
115
|
+
scrollbar-width: thin;
|
|
116
|
+
scrollbar-color: var(--border-strong) transparent;
|
|
117
|
+
}
|
|
118
|
+
.todo-panel__list::-webkit-scrollbar { width: 6px; }
|
|
119
|
+
.todo-panel__list::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }
|
|
120
|
+
.todo-panel__footer {
|
|
121
|
+
padding: var(--sp-2) var(--sp-3);
|
|
122
|
+
border-top: 1px solid var(--border);
|
|
123
|
+
flex-shrink: 0;
|
|
124
|
+
display: flex;
|
|
125
|
+
justify-content: center;
|
|
126
|
+
}
|
|
127
|
+
.todo-empty {
|
|
128
|
+
text-align: center;
|
|
129
|
+
color: var(--text-muted);
|
|
130
|
+
font-size: 12px;
|
|
131
|
+
padding: var(--sp-8) var(--sp-4);
|
|
132
|
+
line-height: 1.6;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/* Todo item */
|
|
136
|
+
.todo-item {
|
|
137
|
+
display: flex;
|
|
138
|
+
align-items: flex-start;
|
|
139
|
+
gap: var(--sp-2);
|
|
140
|
+
padding: var(--sp-2) var(--sp-1);
|
|
141
|
+
border-radius: var(--r-md);
|
|
142
|
+
font-size: 12.5px;
|
|
143
|
+
line-height: 1.4;
|
|
144
|
+
transition: background 0.12s ease;
|
|
145
|
+
}
|
|
146
|
+
.todo-item:hover { background: var(--bg-hover); }
|
|
147
|
+
.todo-item__checkbox {
|
|
148
|
+
margin-top: 2px;
|
|
149
|
+
accent-color: var(--accent);
|
|
150
|
+
cursor: pointer;
|
|
151
|
+
flex-shrink: 0;
|
|
152
|
+
}
|
|
153
|
+
.todo-item__content { flex: 1; min-width: 0; word-break: break-word; }
|
|
154
|
+
.todo-item__content--done { text-decoration: line-through; opacity: 0.6; }
|
|
155
|
+
.todo-item__status {
|
|
156
|
+
font-size: 9.5px;
|
|
157
|
+
padding: 1px 6px;
|
|
158
|
+
border-radius: var(--r-full);
|
|
159
|
+
font-weight: 600;
|
|
160
|
+
flex-shrink: 0;
|
|
161
|
+
line-height: 1.5;
|
|
162
|
+
}
|
|
163
|
+
.todo-item__status--pending { background: var(--accent-soft); color: var(--accent); }
|
|
164
|
+
.todo-item__status--in_progress { background: var(--todo-in-progress-bg); color: var(--todo-in-progress-text); }
|
|
165
|
+
.todo-item__status--completed { background: var(--todo-completed-bg); color: var(--todo-completed-text); }
|
|
166
|
+
.todo-item__status--cancelled { background: var(--danger-soft); color: var(--danger); }
|
|
167
|
+
.todo-item__delete {
|
|
168
|
+
opacity: 0;
|
|
169
|
+
background: none; border: none;
|
|
170
|
+
cursor: pointer;
|
|
171
|
+
color: var(--text-muted);
|
|
172
|
+
padding: 2px;
|
|
173
|
+
font-size: 14px;
|
|
174
|
+
line-height: 1;
|
|
175
|
+
border-radius: var(--r-xs);
|
|
176
|
+
transition: opacity 0.12s ease, background 0.12s ease;
|
|
177
|
+
}
|
|
178
|
+
.todo-item:hover .todo-item__delete { opacity: 1; }
|
|
179
|
+
.todo-item__delete:hover { background: var(--bg-hover); color: var(--danger); }
|
|
180
|
+
|
|
181
|
+
/* ============ Responsive (see 16-mobile.css for ≤768px) ============ */
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
/* Attachment composer: files, folder, paste, drag-drop */
|
|
2
|
+
/* pendingAttachments 在 01q-inflight.js 中声明 */
|
|
3
|
+
|
|
4
|
+
function fileNeedsVision(mime) {
|
|
5
|
+
return mime.startsWith('image/') || mime.startsWith('video/');
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
function fileNeedsImageOnly(mime) {
|
|
9
|
+
return mime.startsWith('image/');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function fileNeedsVideo(mime) {
|
|
13
|
+
return mime.startsWith('video/');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function fileNeedsAudio(mime) {
|
|
17
|
+
return mime.startsWith('audio/');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function fileIsDocOnly(mime) {
|
|
21
|
+
return mime === 'application/pdf' || mime.startsWith('text/');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function canStageFile(mime) {
|
|
25
|
+
if (fileIsDocOnly(mime)) return true;
|
|
26
|
+
if (fileNeedsImageOnly(mime)) {
|
|
27
|
+
return typeof attachmentImageReady === 'function' && attachmentImageReady();
|
|
28
|
+
}
|
|
29
|
+
if (fileNeedsVideo(mime)) {
|
|
30
|
+
return typeof attachmentVideoReady === 'function' && attachmentVideoReady();
|
|
31
|
+
}
|
|
32
|
+
if (fileNeedsAudio(mime)) {
|
|
33
|
+
return typeof audioModelReadyForAttachments === 'function' && audioModelReadyForAttachments();
|
|
34
|
+
}
|
|
35
|
+
return typeof attachmentImageReady === 'function' && attachmentImageReady();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function updateAttachmentUiGate() {
|
|
39
|
+
const imageReady = typeof attachmentImageReady === 'function' && attachmentImageReady();
|
|
40
|
+
const videoReady = typeof attachmentVideoReady === 'function' && attachmentVideoReady();
|
|
41
|
+
const audioReady = typeof audioModelReadyForAttachments === 'function' && audioModelReadyForAttachments();
|
|
42
|
+
const enabled = imageReady || videoReady || audioReady;
|
|
43
|
+
const btnInline = document.getElementById('attachBtnInline');
|
|
44
|
+
if (btnInline) {
|
|
45
|
+
if (enabled) {
|
|
46
|
+
btnInline.classList.remove('is-disabled');
|
|
47
|
+
btnInline.title = '附加文件、拍照或录制视频';
|
|
48
|
+
} else {
|
|
49
|
+
btnInline.classList.add('is-disabled');
|
|
50
|
+
btnInline.title = '请先配置识图(多模态 LLM 或 MiniMax MCP)或音频转写';
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function updateComposeHeadVisibility() {
|
|
56
|
+
const head = document.getElementById('composeHead');
|
|
57
|
+
const att = document.getElementById('composeAttachments');
|
|
58
|
+
if (!head || !att) return;
|
|
59
|
+
head.hidden = att.style.display === 'none';
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function renderAttachmentPreview() {
|
|
63
|
+
const bar = document.getElementById('composeAttachments');
|
|
64
|
+
if (!bar) return;
|
|
65
|
+
bar.innerHTML = '';
|
|
66
|
+
if (!pendingAttachments.length) {
|
|
67
|
+
bar.style.display = 'none';
|
|
68
|
+
updateComposeHeadVisibility();
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
bar.style.display = 'flex';
|
|
72
|
+
pendingAttachments.forEach(function(item, idx) {
|
|
73
|
+
const chip = document.createElement('span');
|
|
74
|
+
chip.className = 'compose-attach-chip';
|
|
75
|
+
if (item.previewUrl) {
|
|
76
|
+
const img = document.createElement('img');
|
|
77
|
+
img.src = item.previewUrl;
|
|
78
|
+
img.alt = item.filename || '';
|
|
79
|
+
chip.appendChild(img);
|
|
80
|
+
} else {
|
|
81
|
+
chip.classList.add('compose-attach-chip--file');
|
|
82
|
+
}
|
|
83
|
+
const label = document.createElement('span');
|
|
84
|
+
label.textContent = item.filename || 'file';
|
|
85
|
+
chip.appendChild(label);
|
|
86
|
+
const rm = document.createElement('button');
|
|
87
|
+
rm.type = 'button';
|
|
88
|
+
rm.className = 'compose-attach-rm';
|
|
89
|
+
rm.textContent = '×';
|
|
90
|
+
rm.addEventListener('click', function() {
|
|
91
|
+
pendingAttachments.splice(idx, 1);
|
|
92
|
+
renderAttachmentPreview();
|
|
93
|
+
});
|
|
94
|
+
chip.appendChild(rm);
|
|
95
|
+
bar.appendChild(chip);
|
|
96
|
+
});
|
|
97
|
+
updateComposeHeadVisibility();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function fileToBase64(file) {
|
|
101
|
+
return new Promise(function(resolve, reject) {
|
|
102
|
+
const r = new FileReader();
|
|
103
|
+
r.onload = function() {
|
|
104
|
+
const s = String(r.result || '');
|
|
105
|
+
const i = s.indexOf(',');
|
|
106
|
+
resolve(i >= 0 ? s.slice(i + 1) : s);
|
|
107
|
+
};
|
|
108
|
+
r.onerror = reject;
|
|
109
|
+
r.readAsDataURL(file);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async function stageFiles(files) {
|
|
114
|
+
for (let i = 0; i < files.length; i++) {
|
|
115
|
+
const f = files[i];
|
|
116
|
+
if (!f || !f.size) continue;
|
|
117
|
+
const mime = f.type || '';
|
|
118
|
+
if (mime === 'image/svg+xml') continue;
|
|
119
|
+
if (!canStageFile(mime)) {
|
|
120
|
+
if (fileNeedsAudio(mime)) systemMsg('err', '请先选择音频转写模型');
|
|
121
|
+
else systemMsg('err', '请先配置识图(多模态 LLM 或 MiniMax MCP)');
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
try {
|
|
125
|
+
const data_base64 = await fileToBase64(f);
|
|
126
|
+
let previewUrl = '';
|
|
127
|
+
if (mime.startsWith('image/')) previewUrl = URL.createObjectURL(f);
|
|
128
|
+
pendingAttachments.push({
|
|
129
|
+
filename: f.name || 'upload',
|
|
130
|
+
mime: mime,
|
|
131
|
+
data_base64: data_base64,
|
|
132
|
+
previewUrl: previewUrl,
|
|
133
|
+
});
|
|
134
|
+
} catch (_) {}
|
|
135
|
+
}
|
|
136
|
+
renderAttachmentPreview();
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async function uploadPendingAttachments() {
|
|
140
|
+
if (!pendingAttachments.length) return [];
|
|
141
|
+
const payload = {
|
|
142
|
+
session_id: sessionId,
|
|
143
|
+
agent_id: agentId,
|
|
144
|
+
files: pendingAttachments.map(function(p) {
|
|
145
|
+
return { filename: p.filename, mime: p.mime, data_base64: p.data_base64 };
|
|
146
|
+
}),
|
|
147
|
+
};
|
|
148
|
+
const r = await fetch('/api/attachments/batch', {
|
|
149
|
+
method: 'POST',
|
|
150
|
+
headers: { 'Content-Type': 'application/json' },
|
|
151
|
+
credentials: 'same-origin',
|
|
152
|
+
body: JSON.stringify(payload),
|
|
153
|
+
});
|
|
154
|
+
const j = await r.json().catch(function() { return {}; });
|
|
155
|
+
if (!r.ok) throw new Error(j.detail || r.statusText);
|
|
156
|
+
if (j.truncated) systemMsg('info', '部分文件因数量上限未上传');
|
|
157
|
+
pendingAttachments.length = 0;
|
|
158
|
+
renderAttachmentPreview();
|
|
159
|
+
return j.attachment_ids || [];
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
(function initAttachmentUi() {
|
|
163
|
+
const fileInput = document.getElementById('attachFileInput');
|
|
164
|
+
const folderInput = document.getElementById('attachFolderInput');
|
|
165
|
+
const nativeCameraInput = document.getElementById('nativeCameraInput');
|
|
166
|
+
const nativeVideoInput = document.getElementById('nativeVideoInput');
|
|
167
|
+
const composeBox = document.querySelector('.compose__box');
|
|
168
|
+
const attachBtn = document.getElementById('attachBtnInline');
|
|
169
|
+
const popup = document.getElementById('attachPopup');
|
|
170
|
+
|
|
171
|
+
let popupOpen = false;
|
|
172
|
+
|
|
173
|
+
function openPopup() {
|
|
174
|
+
if (!popup || !attachBtn) return;
|
|
175
|
+
var rect = attachBtn.getBoundingClientRect();
|
|
176
|
+
popup.style.display = 'flex';
|
|
177
|
+
popup.style.flexDirection = 'column';
|
|
178
|
+
popup.style.left = Math.max(4, rect.left) + 'px';
|
|
179
|
+
popup.style.bottom = (window.innerHeight - rect.top + 6) + 'px';
|
|
180
|
+
popupOpen = true;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function closePopup() {
|
|
184
|
+
popupOpen = false;
|
|
185
|
+
if (popup) popup.style.display = 'none';
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function togglePopup(e) {
|
|
189
|
+
e.stopPropagation();
|
|
190
|
+
if (popupOpen) { closePopup(); return; }
|
|
191
|
+
openPopup();
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// "+" 按钮点击切换弹出菜单
|
|
195
|
+
attachBtn && attachBtn.addEventListener('click', togglePopup);
|
|
196
|
+
|
|
197
|
+
// 弹出菜单选项点击
|
|
198
|
+
popup && popup.addEventListener('click', function(e) {
|
|
199
|
+
const option = e.target.closest('.compose__attach-option');
|
|
200
|
+
if (!option) return;
|
|
201
|
+
const action = option.getAttribute('data-action');
|
|
202
|
+
closePopup();
|
|
203
|
+
if (action === 'file' && fileInput) {
|
|
204
|
+
fileInput.click();
|
|
205
|
+
} else if (action === 'camera') {
|
|
206
|
+
if (typeof launchCameraCapture === 'function') {
|
|
207
|
+
launchCameraCapture('photo');
|
|
208
|
+
} else if (typeof openCameraModal === 'function') {
|
|
209
|
+
openCameraModal('photo');
|
|
210
|
+
} else if (nativeCameraInput) {
|
|
211
|
+
nativeCameraInput.click();
|
|
212
|
+
}
|
|
213
|
+
} else if (action === 'video') {
|
|
214
|
+
if (typeof launchCameraCapture === 'function') {
|
|
215
|
+
launchCameraCapture('video');
|
|
216
|
+
} else if (typeof openCameraModal === 'function') {
|
|
217
|
+
openCameraModal('video');
|
|
218
|
+
} else if (nativeVideoInput) {
|
|
219
|
+
nativeVideoInput.click();
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
// 点击外部关闭弹出菜单
|
|
225
|
+
document.addEventListener('click', function(e) {
|
|
226
|
+
if (!popupOpen) return;
|
|
227
|
+
if (attachBtn && attachBtn.contains(e.target)) return;
|
|
228
|
+
if (popup && popup.contains(e.target)) return;
|
|
229
|
+
closePopup();
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
// 按 Escape 关闭
|
|
233
|
+
document.addEventListener('keydown', function(e) {
|
|
234
|
+
if (e.key === 'Escape' && popupOpen) closePopup();
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
// 文件输入变化处理
|
|
238
|
+
fileInput && fileInput.addEventListener('change', function() {
|
|
239
|
+
if (fileInput.files) stageFiles(Array.from(fileInput.files));
|
|
240
|
+
fileInput.value = '';
|
|
241
|
+
});
|
|
242
|
+
folderInput && folderInput.addEventListener('change', function() {
|
|
243
|
+
if (folderInput.files) stageFiles(Array.from(folderInput.files));
|
|
244
|
+
folderInput.value = '';
|
|
245
|
+
});
|
|
246
|
+
nativeCameraInput && nativeCameraInput.addEventListener('change', function() {
|
|
247
|
+
if (nativeCameraInput.files && nativeCameraInput.files.length && typeof stageFiles === 'function') {
|
|
248
|
+
stageFiles(Array.from(nativeCameraInput.files));
|
|
249
|
+
}
|
|
250
|
+
nativeCameraInput.value = '';
|
|
251
|
+
});
|
|
252
|
+
nativeVideoInput && nativeVideoInput.addEventListener('change', function() {
|
|
253
|
+
if (nativeVideoInput.files && nativeVideoInput.files.length && typeof stageFiles === 'function') {
|
|
254
|
+
stageFiles(Array.from(nativeVideoInput.files));
|
|
255
|
+
}
|
|
256
|
+
nativeVideoInput.value = '';
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
composeBox && composeBox.addEventListener('paste', function(e) {
|
|
260
|
+
const items = (e.clipboardData && e.clipboardData.items) ? Array.from(e.clipboardData.items) : [];
|
|
261
|
+
const files = [];
|
|
262
|
+
items.forEach(function(it) {
|
|
263
|
+
if (it.kind === 'file') {
|
|
264
|
+
const f = it.getAsFile();
|
|
265
|
+
if (f) files.push(f);
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
if (files.length) {
|
|
269
|
+
e.preventDefault();
|
|
270
|
+
stageFiles(files);
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
composeBox && composeBox.addEventListener('dragover', function(e) {
|
|
275
|
+
e.preventDefault();
|
|
276
|
+
});
|
|
277
|
+
composeBox && composeBox.addEventListener('drop', function(e) {
|
|
278
|
+
e.preventDefault();
|
|
279
|
+
const files = (e.dataTransfer && e.dataTransfer.files) ? Array.from(e.dataTransfer.files) : [];
|
|
280
|
+
if (files.length) stageFiles(files);
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
refreshVisionModelSelect().catch(function() {});
|
|
284
|
+
})();
|
|
285
|
+
|
|
286
|
+
function renderUserAttachmentsInBubble(container, attachments) {
|
|
287
|
+
if (!attachments || !attachments.length) return;
|
|
288
|
+
const wrap = document.createElement('div');
|
|
289
|
+
wrap.className = 'bubble-user__attachments';
|
|
290
|
+
attachments.forEach(function(a) {
|
|
291
|
+
if (!a || a.kind !== 'image') return;
|
|
292
|
+
const img = document.createElement('img');
|
|
293
|
+
img.className = 'chat-inline-img bubble-user__img';
|
|
294
|
+
img.alt = a.filename || a.id || '';
|
|
295
|
+
img.src = '/api/attachments/' + encodeURIComponent(a.id)
|
|
296
|
+
+ '?session_id=' + encodeURIComponent(sessionId)
|
|
297
|
+
+ '&agent_id=' + encodeURIComponent(agentId);
|
|
298
|
+
wrap.appendChild(img);
|
|
299
|
+
});
|
|
300
|
+
if (wrap.childNodes.length) {
|
|
301
|
+
container.insertBefore(wrap, container.firstChild);
|
|
302
|
+
if (typeof enhanceChatImagesInBubble === 'function') enhanceChatImagesInBubble(wrap);
|
|
303
|
+
}
|
|
304
|
+
}
|