@teamclaws/teamclaw 2026.8.0 → 2026.11.0
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.
- package/cli.mjs +46 -15
- package/dist/api.js +1 -0
- package/dist/index.js +325 -0
- package/dist/src/config.js +412 -0
- package/dist/src/controller/clarification-routes.js +315 -0
- package/dist/src/controller/controller-capacity.js +14 -0
- package/dist/src/controller/controller-intake.js +895 -0
- package/dist/src/controller/controller-planning.js +813 -0
- package/dist/src/controller/controller-runs.js +175 -0
- package/dist/src/controller/controller-service.js +624 -0
- package/dist/src/controller/controller-tools.js +587 -0
- package/dist/src/controller/delivery-report.js +458 -0
- package/dist/src/controller/github-auth.js +564 -0
- package/dist/src/controller/http-server.js +284 -0
- package/dist/src/controller/kickoff-orchestrator.js +246 -0
- package/dist/src/controller/managed-gateway-process.js +286 -0
- package/dist/src/controller/message-delivery.js +28 -0
- package/dist/src/controller/message-router.js +38 -0
- package/dist/src/controller/message-routes.js +114 -0
- package/dist/src/controller/orchestration-manifest.js +151 -0
- package/dist/src/controller/preview-manager.js +586 -0
- package/dist/src/controller/preview-proxy.js +98 -0
- package/dist/src/controller/profile-switch.js +289 -0
- package/dist/src/controller/project-registry.js +294 -0
- package/dist/src/controller/prompt-injector.js +197 -0
- package/dist/src/controller/repo-routes.js +63 -0
- package/dist/src/controller/role-inference.js +246 -0
- package/dist/src/controller/route-table.js +1353 -0
- package/dist/src/controller/task-assignment.js +508 -0
- package/dist/src/controller/task-cleanup.js +258 -0
- package/dist/src/controller/task-execution.js +240 -0
- package/dist/src/controller/task-results.js +461 -0
- package/dist/src/controller/task-router.js +137 -0
- package/dist/src/controller/task-routes.js +703 -0
- package/dist/src/controller/teamauto-routes.js +124 -0
- package/dist/src/controller/tunnel-manager.js +548 -0
- package/dist/src/controller/ui-assets.js +68 -0
- package/dist/src/controller/websocket.js +42 -0
- package/dist/src/controller/worker-provisioning.js +1674 -0
- package/dist/src/controller/worker-routes.js +188 -0
- package/dist/src/discovery.js +86 -0
- package/dist/src/git-collaboration.js +694 -0
- package/dist/src/identity.js +132 -0
- package/dist/src/install-defaults.js +1 -0
- package/dist/src/interaction-contracts.js +531 -0
- package/dist/src/networking.js +91 -0
- package/dist/src/openclaw-workspace.js +925 -0
- package/dist/src/profile-loader.js +486 -0
- package/dist/src/profiles/banking.json +178 -0
- package/dist/src/profiles/crossborder-ecom.json +253 -0
- package/dist/src/profiles/insurance.json +157 -0
- package/dist/src/profiles/knowledge/hs-structure.md +97 -0
- package/dist/src/profiles/knowledge/incoterms-2020.md +188 -0
- package/dist/src/profiles/knowledge/vat-principles.md +85 -0
- package/dist/src/profiles/schema.json +201 -0
- package/dist/src/profiles/securities.json +137 -0
- package/dist/src/profiles/software-rd.json +264 -0
- package/dist/src/profiles/trading-co.json +200 -0
- package/dist/src/prompt-policy.js +386 -0
- package/dist/src/protocol.js +58 -0
- package/dist/src/role-ids.js +29 -0
- package/dist/src/roles.js +390 -0
- package/dist/src/session-roles.js +14 -0
- package/dist/src/state.js +361 -0
- package/dist/src/task-executor.js +1023 -0
- package/dist/src/teamauto/github-client.js +210 -0
- package/dist/src/teamauto/norms.js +85 -0
- package/dist/src/teamauto/repo-sync.js +423 -0
- package/dist/src/teamauto/scanner.js +207 -0
- package/dist/src/teamauto/schedule.js +123 -0
- package/dist/src/teamauto/scheduler.js +907 -0
- package/dist/src/teamauto/store.js +133 -0
- package/dist/src/types.js +290 -0
- package/dist/src/ui/app.js +4860 -0
- package/dist/src/ui/assets/teamclaw-app-icon.png +0 -0
- package/dist/src/ui/github-login.html +296 -0
- package/dist/src/ui/index.html +447 -0
- package/dist/src/ui/style.css +2805 -0
- package/dist/src/worker/http-handler.js +146 -0
- package/dist/src/worker/message-queue.js +24 -0
- package/dist/src/worker/prompt-injector.js +78 -0
- package/dist/src/worker/skill-installer.js +255 -0
- package/dist/src/worker/tools.js +541 -0
- package/dist/src/worker/worker-service.js +307 -0
- package/dist/src/workspace-browser.js +269 -0
- package/openclaw.plugin.json +28 -1
- package/package.json +3 -2
- package/src/config.ts +33 -2
- package/src/controller/clarification-routes.ts +404 -0
- package/src/controller/controller-intake.ts +1113 -0
- package/src/controller/controller-planning.ts +1029 -0
- package/src/controller/controller-runs.ts +239 -0
- package/src/controller/controller-service.ts +295 -41
- package/src/controller/controller-tools.ts +11 -7
- package/src/controller/http-server.ts +294 -6971
- package/src/controller/kickoff-orchestrator.ts +70 -7
- package/src/controller/message-delivery.ts +49 -0
- package/src/controller/message-routes.ts +137 -0
- package/src/controller/orchestration-manifest.ts +6 -29
- package/src/controller/preview-proxy.ts +127 -0
- package/src/controller/profile-switch.ts +366 -0
- package/src/controller/project-registry.ts +361 -0
- package/src/controller/prompt-injector.ts +23 -8
- package/src/controller/repo-routes.ts +91 -0
- package/src/controller/role-inference.ts +260 -22
- package/src/controller/route-table.ts +1616 -0
- package/src/controller/task-assignment.ts +618 -0
- package/src/controller/task-cleanup.ts +344 -0
- package/src/controller/task-execution.ts +356 -0
- package/src/controller/task-results.ts +544 -0
- package/src/controller/task-router.ts +98 -6
- package/src/controller/task-routes.ts +812 -0
- package/src/controller/teamauto-routes.ts +121 -0
- package/src/controller/ui-assets.ts +70 -0
- package/src/controller/websocket.ts +13 -1
- package/src/controller/worker-provisioning.ts +32 -4
- package/src/controller/worker-routes.ts +241 -0
- package/src/identity.ts +3 -2
- package/src/interaction-contracts.ts +7 -7
- package/src/openclaw-workspace.ts +44 -18
- package/src/profile-loader.ts +650 -0
- package/src/profiles/banking.json +178 -0
- package/src/profiles/crossborder-ecom.json +253 -0
- package/src/profiles/insurance.json +157 -0
- package/src/profiles/knowledge/hs-structure.md +97 -0
- package/src/profiles/knowledge/incoterms-2020.md +188 -0
- package/src/profiles/knowledge/vat-principles.md +85 -0
- package/src/profiles/schema.json +201 -0
- package/src/profiles/securities.json +137 -0
- package/src/profiles/software-rd.json +264 -0
- package/src/profiles/trading-co.json +200 -0
- package/src/prompt-policy.ts +27 -13
- package/src/role-ids.ts +31 -0
- package/src/roles.ts +60 -14
- package/src/session-roles.ts +14 -0
- package/src/state.ts +236 -9
- package/src/task-executor.ts +7 -18
- package/src/teamauto/github-client.ts +21 -0
- package/src/teamauto/repo-sync.ts +246 -6
- package/src/teamauto/scanner.ts +47 -13
- package/src/teamauto/scheduler.ts +259 -16
- package/src/teamauto/store.ts +12 -0
- package/src/types.ts +133 -16
- package/src/ui/app.js +592 -24
- package/src/ui/index.html +44 -11
- package/src/ui/style.css +194 -0
- package/src/worker/prompt-injector.ts +48 -8
- package/src/worker/skill-installer.ts +3 -1
- package/src/worker/worker-service.ts +83 -3
package/src/ui/app.js
CHANGED
|
@@ -9,7 +9,16 @@
|
|
|
9
9
|
let terminalTasksVisible = 20;
|
|
10
10
|
let activeTab = "tasks";
|
|
11
11
|
let teamState = { workers: [], tasks: [], controllerRuns: [], messages: [], clarifications: [], modelReadiness: null, externalWorkerInstall: null };
|
|
12
|
-
|
|
12
|
+
// Role registry mirror (GET /api/v1/roles) — single data source for the
|
|
13
|
+
// manual-task role options, kickoff icons, and the external-worker role
|
|
14
|
+
// default. Kept empty until the first successful /roles response; renders
|
|
15
|
+
// that need it degrade to the Auto-assign option / the generic icon.
|
|
16
|
+
let roleRegistry = [];
|
|
17
|
+
// Optional default role id advertised by the backend (e.g. profile default
|
|
18
|
+
// once /roles returns profile content); empty when the field is absent,
|
|
19
|
+
// in which case the first registry entry is the default.
|
|
20
|
+
let roleDefaultId = "";
|
|
21
|
+
let selectedExternalWorkerRole = "";
|
|
13
22
|
let selectedExternalWorkerDiscoveryMode = "mdns";
|
|
14
23
|
let externalWorkerInstallVisible = false;
|
|
15
24
|
let selectedTaskId = null;
|
|
@@ -21,6 +30,16 @@
|
|
|
21
30
|
let selectedWorkspaceFile = null;
|
|
22
31
|
let selectedWorkspaceView = "source";
|
|
23
32
|
let workspaceLoaded = false;
|
|
33
|
+
// Team profile switcher (Phase 5.1): registry mirror of GET /api/v1/profiles
|
|
34
|
+
// and the latest GET /api/v1/team/profile response (active profile detail
|
|
35
|
+
// incl. capabilities + transition tracking). Empty until the first
|
|
36
|
+
// successful fetch; capability-gated entries stay visible meanwhile so
|
|
37
|
+
// older controllers behave exactly as before.
|
|
38
|
+
let teamProfileRegistry = [];
|
|
39
|
+
let activeTeamProfile = null;
|
|
40
|
+
let pendingSwitchTarget = null;
|
|
41
|
+
let pendingSwitchProfileId = "";
|
|
42
|
+
let teamProfileSwitchInFlight = false;
|
|
24
43
|
let clarificationPromptOpen = false;
|
|
25
44
|
let activeClarificationId = null;
|
|
26
45
|
let dismissedClarificationIds = [];
|
|
@@ -147,7 +166,7 @@
|
|
|
147
166
|
"teamauto.scheduleHint": "Schedules: */N * * * * (every N min), M * * * * (hourly at :M), 0 */N * * * (every N h), M H * * * (daily at H:M), @hourly, @daily, @weekly, @monthly. Sweeps align to the clock and survive restarts.",
|
|
148
167
|
"teamauto.loginFirst": "Sign in to GitHub first (top-right Login).",
|
|
149
168
|
"teamauto.loadingRepos": "Loading your repos...",
|
|
150
|
-
"teamauto.noCandidates": "No selectable repos (check GitHub login)
|
|
169
|
+
"teamauto.noCandidates": "No selectable repos (check GitHub login)",
|
|
151
170
|
"teamauto.needRepo": "Select a repository first",
|
|
152
171
|
"teamauto.active": "active",
|
|
153
172
|
"teamauto.disabled": "disabled",
|
|
@@ -157,6 +176,7 @@
|
|
|
157
176
|
"teamauto.enable": "Enable",
|
|
158
177
|
"teamauto.unbind": "Unbind",
|
|
159
178
|
"teamauto.save": "Save config",
|
|
179
|
+
"teamauto.tabConfig": "Config",
|
|
160
180
|
"teamauto.saved": "Saved",
|
|
161
181
|
"teamauto.schedule": "Schedule",
|
|
162
182
|
"teamauto.maxPerSweep": "Max/sweep",
|
|
@@ -194,7 +214,27 @@
|
|
|
194
214
|
"detail.kicker": "Task Details",
|
|
195
215
|
"live.idle": "Idle",
|
|
196
216
|
"clarification.kicker": "Clarification needed",
|
|
197
|
-
"clarification.title": "Human input required"
|
|
217
|
+
"clarification.title": "Human input required",
|
|
218
|
+
"teamProfile.kicker": "Team profile",
|
|
219
|
+
"teamProfile.title": "Switch team profile",
|
|
220
|
+
"teamProfile.headerButtonTitle": "Team profile - click to view or switch",
|
|
221
|
+
"teamProfile.current": "Current",
|
|
222
|
+
"teamProfile.pendingSignoff": "Pending human sign-off",
|
|
223
|
+
"teamProfile.roleCount": "{n} roles",
|
|
224
|
+
"teamProfile.loadFailed": "Failed to load team profiles",
|
|
225
|
+
"teamProfile.confirmArchive": "The current team's {n} task(s) will be archived as read-only history. This cannot be undone.",
|
|
226
|
+
"teamProfile.confirmWorkers": "All workers stop and re-warm for the new team; task submissions are rejected while the switch runs.",
|
|
227
|
+
"teamProfile.capabilityRestartHint": "Capabilities {list} change with this switch: turning one off stops it immediately, and turning one back on only takes effect after a gateway restart.",
|
|
228
|
+
"teamProfile.confirmButton": "Switch team",
|
|
229
|
+
"teamProfile.cancel": "Back",
|
|
230
|
+
"teamProfile.switching": "Switching…",
|
|
231
|
+
"teamProfile.switchStarted": "Switch started - waiting for the new team to warm up…",
|
|
232
|
+
"teamProfile.transitionPending": "A switch to {name} is already in progress (phase: {phase}).",
|
|
233
|
+
"teamProfile.switchCompleted": "Team profile switched to {name}",
|
|
234
|
+
"teamProfile.switchFailed": "Team profile switch to {name} failed",
|
|
235
|
+
"teamProfile.archivedTitle": "Archived teams",
|
|
236
|
+
"teamProfile.archivedEmpty": "No archived teams yet.",
|
|
237
|
+
"teamProfile.archivedTasks": "{n} tasks"
|
|
198
238
|
},
|
|
199
239
|
zh: {
|
|
200
240
|
"action.refresh": "刷新",
|
|
@@ -306,7 +346,7 @@
|
|
|
306
346
|
"teamauto.scheduleHint": "支持的表达式:*/N * * * *(每 N 分钟)、M * * * *(每小时第 M 分)、0 */N * * *(每 N 小时)、M H * * *(每天 H:M)、@hourly、@daily、@weekly、@monthly。扫描按墙钟对齐,重启后自动恢复。",
|
|
307
347
|
"teamauto.loginFirst": "请先登录 GitHub(右上角 Login)。",
|
|
308
348
|
"teamauto.loadingRepos": "正在加载你的仓库...",
|
|
309
|
-
"teamauto.noCandidates": "无可选仓库(请检查 GitHub
|
|
349
|
+
"teamauto.noCandidates": "无可选仓库(请检查 GitHub 登录)",
|
|
310
350
|
"teamauto.needRepo": "请先选择一个仓库",
|
|
311
351
|
"teamauto.active": "运行中",
|
|
312
352
|
"teamauto.disabled": "已停用",
|
|
@@ -316,6 +356,7 @@
|
|
|
316
356
|
"teamauto.enable": "启用",
|
|
317
357
|
"teamauto.unbind": "解绑",
|
|
318
358
|
"teamauto.save": "保存配置",
|
|
359
|
+
"teamauto.tabConfig": "配置",
|
|
319
360
|
"teamauto.saved": "已保存",
|
|
320
361
|
"teamauto.schedule": "节奏",
|
|
321
362
|
"teamauto.maxPerSweep": "每轮上限",
|
|
@@ -326,7 +367,7 @@
|
|
|
326
367
|
"teamauto.confirmUnbind": "确定解绑该仓库?",
|
|
327
368
|
"teamauto.empty": "尚未绑定仓库。在上方选择后点击绑定。",
|
|
328
369
|
"teamauto.activity": "动态",
|
|
329
|
-
"teamauto.activityEmpty": "暂无 TeamAuto
|
|
370
|
+
"teamauto.activityEmpty": "暂无 TeamAuto 动态 - 扫描与写回会出现在这里。",
|
|
330
371
|
"worker.add": "添加 worker",
|
|
331
372
|
"worker.hide": "隐藏 worker 命令",
|
|
332
373
|
"worker.cardTitle": "注册新的外部 worker",
|
|
@@ -353,7 +394,27 @@
|
|
|
353
394
|
"detail.kicker": "任务详情",
|
|
354
395
|
"live.idle": "空闲",
|
|
355
396
|
"clarification.kicker": "需要澄清",
|
|
356
|
-
"clarification.title": "需要人工输入"
|
|
397
|
+
"clarification.title": "需要人工输入",
|
|
398
|
+
"teamProfile.kicker": "团队画像",
|
|
399
|
+
"teamProfile.title": "切换团队画像",
|
|
400
|
+
"teamProfile.headerButtonTitle": "团队画像 - 点击查看或切换",
|
|
401
|
+
"teamProfile.current": "当前",
|
|
402
|
+
"teamProfile.pendingSignoff": "待人工签署",
|
|
403
|
+
"teamProfile.roleCount": "{n} 个角色",
|
|
404
|
+
"teamProfile.loadFailed": "加载团队画像失败",
|
|
405
|
+
"teamProfile.confirmArchive": "当前团队的 {n} 个任务将归档为只读历史,此操作不可撤销。",
|
|
406
|
+
"teamProfile.confirmWorkers": "所有 worker 将停止并按新团队重新预热;切换期间提交的任务会被拒绝。",
|
|
407
|
+
"teamProfile.capabilityRestartHint": "能力 {list} 将随本次切换变化:关闭会立即停用,重新开启需重启网关才会生效。",
|
|
408
|
+
"teamProfile.confirmButton": "切换团队",
|
|
409
|
+
"teamProfile.cancel": "返回",
|
|
410
|
+
"teamProfile.switching": "切换中…",
|
|
411
|
+
"teamProfile.switchStarted": "切换已开始 - 等待新团队预热完成…",
|
|
412
|
+
"teamProfile.transitionPending": "到 {name} 的切换正在进行中(阶段:{phase})。",
|
|
413
|
+
"teamProfile.switchCompleted": "团队画像已切换到 {name}",
|
|
414
|
+
"teamProfile.switchFailed": "切换到 {name} 的团队画像失败",
|
|
415
|
+
"teamProfile.archivedTitle": "已归档团队",
|
|
416
|
+
"teamProfile.archivedEmpty": "暂无已归档团队。",
|
|
417
|
+
"teamProfile.archivedTasks": "{n} 个任务"
|
|
357
418
|
}
|
|
358
419
|
};
|
|
359
420
|
|
|
@@ -1017,19 +1078,12 @@
|
|
|
1017
1078
|
});
|
|
1018
1079
|
}
|
|
1019
1080
|
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
devops: "⚙️",
|
|
1027
|
-
"tech-lead": "👨💻",
|
|
1028
|
-
"data-engineer": "📊",
|
|
1029
|
-
"ml-engineer": "🤖",
|
|
1030
|
-
"infra-engineer": "🖧",
|
|
1031
|
-
"dba": "🗄️",
|
|
1032
|
-
};
|
|
1081
|
+
// Role icons come from the /roles registry (RoleDefinition.icon) instead of
|
|
1082
|
+
// a hand-maintained per-UI map, so profile role sets render their own icons.
|
|
1083
|
+
function roleIcon(roleId) {
|
|
1084
|
+
var role = roleRegistry.find(function (entry) { return entry.id === roleId; });
|
|
1085
|
+
return (role && role.icon) || "👤";
|
|
1086
|
+
}
|
|
1033
1087
|
|
|
1034
1088
|
function renderKickoffMeetingPanel(kickoffPlan) {
|
|
1035
1089
|
if (!kickoffPlan || !Array.isArray(kickoffPlan.assessments) || kickoffPlan.assessments.length === 0) {
|
|
@@ -1053,7 +1107,7 @@
|
|
|
1053
1107
|
"</div>";
|
|
1054
1108
|
|
|
1055
1109
|
var roleCards = assessments.map(function (a) {
|
|
1056
|
-
var icon =
|
|
1110
|
+
var icon = roleIcon(a.role);
|
|
1057
1111
|
var statusCls = a.needed ? "kickoff-role-needed" : "kickoff-role-dismissed";
|
|
1058
1112
|
var statusLabel = a.needed ? "Confirmed" : "Not Needed";
|
|
1059
1113
|
|
|
@@ -1206,7 +1260,7 @@
|
|
|
1206
1260
|
if (manifest.requiredRoles && manifest.requiredRoles.length) {
|
|
1207
1261
|
reqLines.push('<div class="planning-req-section"><div class="planning-req-label">' + escapeHtml(t("planning.requiredRoles")) + "</div>");
|
|
1208
1262
|
reqLines.push('<div class="kickoff-deps">' + manifest.requiredRoles.map(function (r) {
|
|
1209
|
-
var icon =
|
|
1263
|
+
var icon = roleIcon(r);
|
|
1210
1264
|
return '<span class="kickoff-dep-chip">' + icon + " " + escapeHtml(r) + "</span>";
|
|
1211
1265
|
}).join("") + "</div></div>");
|
|
1212
1266
|
}
|
|
@@ -1284,7 +1338,7 @@
|
|
|
1284
1338
|
|
|
1285
1339
|
// Role cards
|
|
1286
1340
|
assessments.forEach(function (a) {
|
|
1287
|
-
var icon =
|
|
1341
|
+
var icon = roleIcon(a.role);
|
|
1288
1342
|
var statusCls = a.needed ? "kickoff-role-needed" : "kickoff-role-dismissed";
|
|
1289
1343
|
var statusLabel = a.needed ? "Confirmed" : "Not Needed";
|
|
1290
1344
|
|
|
@@ -2055,7 +2109,7 @@
|
|
|
2055
2109
|
return;
|
|
2056
2110
|
}
|
|
2057
2111
|
if (!roles.some(function (role) { return role.id === selectedExternalWorkerRole; })) {
|
|
2058
|
-
selectedExternalWorkerRole = roles
|
|
2112
|
+
selectedExternalWorkerRole = resolveDefaultRoleId(roles, info.defaultRole);
|
|
2059
2113
|
}
|
|
2060
2114
|
if (selectedExternalWorkerDiscoveryMode === "manual" && !info.recommendedControllerUrl) {
|
|
2061
2115
|
selectedExternalWorkerDiscoveryMode = "mdns";
|
|
@@ -2282,6 +2336,52 @@
|
|
|
2282
2336
|
case "report:ready":
|
|
2283
2337
|
handleReportReady(event.data || {});
|
|
2284
2338
|
break;
|
|
2339
|
+
case "team.switch_started": {
|
|
2340
|
+
// Section 2.3 switch semantics: archive + re-warm in progress. Pull
|
|
2341
|
+
// fresh state so the transition notice surfaces; task submissions
|
|
2342
|
+
// get 503 server-side while the transition runs.
|
|
2343
|
+
const startedData = event.data || {};
|
|
2344
|
+
refreshAll();
|
|
2345
|
+
renderTeamProfileTransitionNotice({
|
|
2346
|
+
phase: "draining",
|
|
2347
|
+
targetProfileId: startedData.profileId || "",
|
|
2348
|
+
});
|
|
2349
|
+
break;
|
|
2350
|
+
}
|
|
2351
|
+
case "team.switch_completed": {
|
|
2352
|
+
// Full re-pull (roles/workers/tasks change wholesale with the new
|
|
2353
|
+
// profile); close the switcher modal when this UI initiated it.
|
|
2354
|
+
const completedProfileId = (event.data || {}).profileId || "";
|
|
2355
|
+
refreshAll();
|
|
2356
|
+
if (teamProfileSwitchInFlight || pendingSwitchProfileId) {
|
|
2357
|
+
finishTeamProfileSwitch(completedProfileId);
|
|
2358
|
+
}
|
|
2359
|
+
showNotice(
|
|
2360
|
+
"team:switch_completed",
|
|
2361
|
+
"success",
|
|
2362
|
+
t("teamProfile.switchCompleted", { name: teamProfileDisplayNameById(completedProfileId) }),
|
|
2363
|
+
"",
|
|
2364
|
+
);
|
|
2365
|
+
break;
|
|
2366
|
+
}
|
|
2367
|
+
case "team.switch_failed": {
|
|
2368
|
+
// Server-side switch failure: release the loading/confirm state with
|
|
2369
|
+
// an explicit failure toast instead of waiting for the reconcile
|
|
2370
|
+
// fallback to silently re-enable the button. The reason may state
|
|
2371
|
+
// that the archive was preserved and the team is partially switched;
|
|
2372
|
+
// the state may have moved partway, so re-pull everything.
|
|
2373
|
+
const failedData = event.data || {};
|
|
2374
|
+
const failedTargetId = failedData.targetProfileId || pendingSwitchProfileId || "";
|
|
2375
|
+
refreshAll();
|
|
2376
|
+
releaseTeamProfileSwitchUi();
|
|
2377
|
+
showNotice(
|
|
2378
|
+
"team:switch_failed",
|
|
2379
|
+
"attention",
|
|
2380
|
+
t("teamProfile.switchFailed", { name: teamProfileDisplayNameById(failedTargetId) }),
|
|
2381
|
+
String(failedData.reason || ""),
|
|
2382
|
+
);
|
|
2383
|
+
break;
|
|
2384
|
+
}
|
|
2285
2385
|
}
|
|
2286
2386
|
}
|
|
2287
2387
|
|
|
@@ -2333,11 +2433,20 @@
|
|
|
2333
2433
|
try {
|
|
2334
2434
|
const statusRes = await apiGet("/team/status");
|
|
2335
2435
|
let rolesRes = { roles: [] };
|
|
2436
|
+
let rolesLoaded = false;
|
|
2336
2437
|
try {
|
|
2337
2438
|
rolesRes = await apiGet("/roles");
|
|
2439
|
+
rolesLoaded = true;
|
|
2338
2440
|
} catch (rolesErr) {
|
|
2339
2441
|
console.error("Failed to load roles:", rolesErr);
|
|
2340
2442
|
}
|
|
2443
|
+
if (rolesLoaded) {
|
|
2444
|
+
// Keep the last known registry when a later refresh fails so the
|
|
2445
|
+
// manual-task options and role icons survive transient /roles errors.
|
|
2446
|
+
roleRegistry = Array.isArray(rolesRes.roles) ? rolesRes.roles : [];
|
|
2447
|
+
roleDefaultId = typeof rolesRes.defaultRole === "string" ? rolesRes.defaultRole : "";
|
|
2448
|
+
renderTaskRoleOptions();
|
|
2449
|
+
}
|
|
2341
2450
|
|
|
2342
2451
|
teamState = {
|
|
2343
2452
|
workers: statusRes.workers || [],
|
|
@@ -2349,6 +2458,22 @@
|
|
|
2349
2458
|
externalWorkerInstall: statusRes.externalWorkerInstall || null,
|
|
2350
2459
|
};
|
|
2351
2460
|
|
|
2461
|
+
// Active team profile (Phase 5.1): drives the header indicator, the
|
|
2462
|
+
// capability-gated tab visibility, and the switch transition notice.
|
|
2463
|
+
// Tolerated like /roles - an older controller without the endpoint
|
|
2464
|
+
// keeps the default (software-rd) presentation.
|
|
2465
|
+
try {
|
|
2466
|
+
activeTeamProfile = await apiGet("/team/profile");
|
|
2467
|
+
} catch (profileErr) {
|
|
2468
|
+
console.error("Failed to load team profile:", profileErr);
|
|
2469
|
+
}
|
|
2470
|
+
if (activeTeamProfile) {
|
|
2471
|
+
applyCapabilitiesVisibility(activeTeamProfile);
|
|
2472
|
+
renderTeamProfileHeaderButton();
|
|
2473
|
+
renderTeamProfileTransitionNotice();
|
|
2474
|
+
reconcileTeamProfileSwitch();
|
|
2475
|
+
}
|
|
2476
|
+
|
|
2352
2477
|
renderWorkers(teamState.workers);
|
|
2353
2478
|
renderTasks(teamState.tasks);
|
|
2354
2479
|
renderPlanningTab(teamState.controllerRuns);
|
|
@@ -2831,8 +2956,10 @@
|
|
|
2831
2956
|
var opts = options || {};
|
|
2832
2957
|
return normalizeArray(items).map(function (item) {
|
|
2833
2958
|
const status = item.status || "pending";
|
|
2959
|
+
// Worker context is written in markdown (headings, bold, lists) - run
|
|
2960
|
+
// it through the shared renderer instead of raw textContent.
|
|
2834
2961
|
const context = item.context
|
|
2835
|
-
? '<div class="clarification-context"><strong>Context:</strong>
|
|
2962
|
+
? '<div class="clarification-context"><strong>Context:</strong><div class="clarification-context-md">' + renderMarkdown(item.context) + "</div></div>"
|
|
2836
2963
|
: "";
|
|
2837
2964
|
const taskLink = opts.linkToTask && item.taskId
|
|
2838
2965
|
? '<button type="button" class="btn btn-small" data-open-task-id="' + escapeHtml(item.taskId) + '">Open task</button>'
|
|
@@ -3099,6 +3226,40 @@
|
|
|
3099
3226
|
}).join("");
|
|
3100
3227
|
}
|
|
3101
3228
|
|
|
3229
|
+
// Manual-task form: role options are generated from the /roles registry
|
|
3230
|
+
// (rendered on each refresh); the Auto-assign placeholder stays in the
|
|
3231
|
+
// static HTML so i18n keeps applying to it. Preserves the current selection
|
|
3232
|
+
// across refreshes when the role is still offered.
|
|
3233
|
+
function renderTaskRoleOptions() {
|
|
3234
|
+
const select = $("#task-role");
|
|
3235
|
+
if (!select) return;
|
|
3236
|
+
const previous = select.value;
|
|
3237
|
+
while (select.options.length > 1) {
|
|
3238
|
+
select.remove(1);
|
|
3239
|
+
}
|
|
3240
|
+
roleRegistry.forEach(function (role) {
|
|
3241
|
+
if (!role || typeof role.id !== "string" || !role.id) return;
|
|
3242
|
+
const option = document.createElement("option");
|
|
3243
|
+
option.value = role.id;
|
|
3244
|
+
option.textContent = role.label || role.id;
|
|
3245
|
+
select.appendChild(option);
|
|
3246
|
+
});
|
|
3247
|
+
if (previous && Array.prototype.some.call(select.options, function (option) { return option.value === previous; })) {
|
|
3248
|
+
select.value = previous;
|
|
3249
|
+
}
|
|
3250
|
+
}
|
|
3251
|
+
|
|
3252
|
+
// Default role for the external-worker install card: prefer the default the
|
|
3253
|
+
// backend advertises on the externalWorkerInstall payload (/team/status),
|
|
3254
|
+
// then one advertised on /roles, else fall back to the first registry entry.
|
|
3255
|
+
function resolveDefaultRoleId(roles, payloadDefaultId) {
|
|
3256
|
+
var preferred = typeof payloadDefaultId === "string" && payloadDefaultId ? payloadDefaultId : roleDefaultId;
|
|
3257
|
+
if (preferred && roles.some(function (role) { return role.id === preferred; })) {
|
|
3258
|
+
return preferred;
|
|
3259
|
+
}
|
|
3260
|
+
return roles.length > 0 ? roles[0].id : "";
|
|
3261
|
+
}
|
|
3262
|
+
|
|
3102
3263
|
function tabNameFromHash() {
|
|
3103
3264
|
const match = /^#\/tab\/([a-z][a-z0-9-]*)$/i.exec(window.location.hash || "");
|
|
3104
3265
|
const name = match ? match[1] : "";
|
|
@@ -3120,6 +3281,20 @@
|
|
|
3120
3281
|
}
|
|
3121
3282
|
|
|
3122
3283
|
function activateTab(nextTab) {
|
|
3284
|
+
// TeamAuto sub-tabs (Config / Activity) - delegated once, DOM-level.
|
|
3285
|
+
// NOTE: guard via function property - document.dataset is undefined on
|
|
3286
|
+
// Document (it only exists on Element) and threw during init, killing
|
|
3287
|
+
// every listener registered after it (user-visible: ALL clicks dead).
|
|
3288
|
+
if (!activateTab.taSubtabsBound) {
|
|
3289
|
+
activateTab.taSubtabsBound = true;
|
|
3290
|
+
document.addEventListener("click", function (event) {
|
|
3291
|
+
const btn = event.target instanceof Element && event.target.closest("[data-ta-pane]");
|
|
3292
|
+
if (!btn || btn.tagName !== "BUTTON") return;
|
|
3293
|
+
const pane = btn.getAttribute("data-ta-pane");
|
|
3294
|
+
$$("[data-ta-pane]").forEach((b) => b.classList.toggle("active", b === btn));
|
|
3295
|
+
$$("[data-ta-pane-body]").forEach((p) => p.classList.toggle("is-hidden", p.getAttribute("data-ta-pane-body") !== pane));
|
|
3296
|
+
});
|
|
3297
|
+
}
|
|
3123
3298
|
activeTab = nextTab || "tasks";
|
|
3124
3299
|
$$(".tab").forEach(function (item) {
|
|
3125
3300
|
item.classList.toggle("active", item.dataset.tab === activeTab);
|
|
@@ -3524,6 +3699,9 @@
|
|
|
3524
3699
|
type: "controller-input",
|
|
3525
3700
|
content: cmd,
|
|
3526
3701
|
});
|
|
3702
|
+
// User spec: sending an intake IS a conversation action - jump to the
|
|
3703
|
+
// Messages tab so the reply lands in view without an extra click.
|
|
3704
|
+
activateTab("messages");
|
|
3527
3705
|
|
|
3528
3706
|
apiPost("/controller/intake", {
|
|
3529
3707
|
message: cmd,
|
|
@@ -3701,9 +3879,399 @@
|
|
|
3701
3879
|
bindWorkspacePrompt();
|
|
3702
3880
|
promptWorkspaceIfDefault();
|
|
3703
3881
|
updateWorkspacePathIndicator();
|
|
3882
|
+
bindTeamProfileModal();
|
|
3704
3883
|
bindModelSettings();
|
|
3705
3884
|
bindGithubCorner();
|
|
3706
3885
|
|
|
3886
|
+
// ==================== Team profile switcher (Phase 5.1) ====================
|
|
3887
|
+
// Header mini-button + modal over the model-settings-modal precedent:
|
|
3888
|
+
// step 1 lists GET /api/v1/profiles cards, step 2 confirms the section 2.3
|
|
3889
|
+
// archive consequences, then POST /api/v1/team/profile is tracked via the
|
|
3890
|
+
// team.switch_started / team.switch_completed WS events. The archived
|
|
3891
|
+
// teams section lists GET /api/v1/archived-teams metadata read-only.
|
|
3892
|
+
|
|
3893
|
+
function profileDisplayLabel(profile) {
|
|
3894
|
+
if (!profile) return "";
|
|
3895
|
+
if (currentLanguage === "zh") {
|
|
3896
|
+
return profile.nameZh || profile.name || profile.id || "";
|
|
3897
|
+
}
|
|
3898
|
+
return profile.name || profile.nameZh || profile.id || "";
|
|
3899
|
+
}
|
|
3900
|
+
|
|
3901
|
+
function teamProfileDisplayNameById(profileId) {
|
|
3902
|
+
if (!profileId) return "";
|
|
3903
|
+
var entry = teamProfileRegistry.filter(function (p) { return p.id === profileId; })[0];
|
|
3904
|
+
if (entry) return profileDisplayLabel(entry);
|
|
3905
|
+
if (activeTeamProfile && activeTeamProfile.profile && activeTeamProfile.profile.id === profileId) {
|
|
3906
|
+
return profileDisplayLabel(activeTeamProfile.profile);
|
|
3907
|
+
}
|
|
3908
|
+
return profileId;
|
|
3909
|
+
}
|
|
3910
|
+
|
|
3911
|
+
// reviewedBy carries the review-trail strings from the profile packs; a
|
|
3912
|
+
// "Human sign-off pending" entry means the finance-domain review is not
|
|
3913
|
+
// countersigned yet and the card must say so rather than hide it.
|
|
3914
|
+
function profileHasPendingSignoff(profile) {
|
|
3915
|
+
return (profile && Array.isArray(profile.reviewedBy) ? profile.reviewedBy : []).some(function (entry) {
|
|
3916
|
+
return String(entry).indexOf("Human sign-off pending") !== -1;
|
|
3917
|
+
});
|
|
3918
|
+
}
|
|
3919
|
+
|
|
3920
|
+
function renderTeamProfileHeaderButton() {
|
|
3921
|
+
var button = $("#team-profile-toggle");
|
|
3922
|
+
if (!button) return;
|
|
3923
|
+
var profile = activeTeamProfile && activeTeamProfile.profile;
|
|
3924
|
+
var icon = profile && profile.icon ? profile.icon + " " : "";
|
|
3925
|
+
var label = profile
|
|
3926
|
+
? profileDisplayLabel(profile)
|
|
3927
|
+
: ((activeTeamProfile && activeTeamProfile.profileId) || "Team");
|
|
3928
|
+
button.textContent = icon + label;
|
|
3929
|
+
button.title = t("teamProfile.headerButtonTitle");
|
|
3930
|
+
}
|
|
3931
|
+
|
|
3932
|
+
// UI contract (design section 4 / P2.3): GET /team/profile carries the
|
|
3933
|
+
// active capabilities and the UI hides capability-gated entries. The
|
|
3934
|
+
// teamauto tab is hidden (NOT removed) so the DOM keeps its full tab set
|
|
3935
|
+
// for contract tests; unknown/missing capabilities default to visible so
|
|
3936
|
+
// software-rd and older controllers behave exactly as before.
|
|
3937
|
+
function applyCapabilitiesVisibility(profileInfo) {
|
|
3938
|
+
var caps = profileInfo && profileInfo.profile && profileInfo.profile.capabilities;
|
|
3939
|
+
var teamautoEnabled = !caps || caps.teamauto !== false;
|
|
3940
|
+
var teamautoTab = $('[data-tab="teamauto"]');
|
|
3941
|
+
if (teamautoTab) {
|
|
3942
|
+
teamautoTab.hidden = !teamautoEnabled;
|
|
3943
|
+
}
|
|
3944
|
+
if (!teamautoEnabled && activeTab === "teamauto") {
|
|
3945
|
+
activateTab("tasks");
|
|
3946
|
+
}
|
|
3947
|
+
}
|
|
3948
|
+
|
|
3949
|
+
function openTeamProfileModal() {
|
|
3950
|
+
var modal = $("#team-profile-modal");
|
|
3951
|
+
if (!modal) return;
|
|
3952
|
+
showTeamProfileListStep();
|
|
3953
|
+
renderTeamProfileTransitionNotice();
|
|
3954
|
+
modal.classList.add("open");
|
|
3955
|
+
modal.setAttribute("aria-hidden", "false");
|
|
3956
|
+
refreshTeamProfileModalData();
|
|
3957
|
+
}
|
|
3958
|
+
|
|
3959
|
+
function closeTeamProfileModal() {
|
|
3960
|
+
var modal = $("#team-profile-modal");
|
|
3961
|
+
if (!modal) return;
|
|
3962
|
+
modal.classList.remove("open");
|
|
3963
|
+
modal.setAttribute("aria-hidden", "true");
|
|
3964
|
+
// A switch in flight keeps its confirm-step state so the completion
|
|
3965
|
+
// event still closes cleanly; otherwise reset for the next open.
|
|
3966
|
+
if (!teamProfileSwitchInFlight) {
|
|
3967
|
+
showTeamProfileListStep();
|
|
3968
|
+
}
|
|
3969
|
+
}
|
|
3970
|
+
|
|
3971
|
+
function refreshTeamProfileModalData() {
|
|
3972
|
+
apiGet("/profiles").then(function (data) {
|
|
3973
|
+
teamProfileRegistry = data && Array.isArray(data.profiles) ? data.profiles : [];
|
|
3974
|
+
renderTeamProfileCards();
|
|
3975
|
+
}).catch(function (err) {
|
|
3976
|
+
var listEl = $("#team-profile-list");
|
|
3977
|
+
if (listEl) {
|
|
3978
|
+
listEl.innerHTML = '<div class="empty-state">' + escapeHtml(t("teamProfile.loadFailed")) + "</div>";
|
|
3979
|
+
}
|
|
3980
|
+
showError(err instanceof Error ? err.message : t("teamProfile.loadFailed"));
|
|
3981
|
+
});
|
|
3982
|
+
renderTeamProfileArchives();
|
|
3983
|
+
}
|
|
3984
|
+
|
|
3985
|
+
function renderTeamProfileCards() {
|
|
3986
|
+
var listEl = $("#team-profile-list");
|
|
3987
|
+
if (!listEl) return;
|
|
3988
|
+
if (!teamProfileRegistry.length) {
|
|
3989
|
+
listEl.innerHTML = '<div class="empty-state">' + escapeHtml(t("teamProfile.loadFailed")) + "</div>";
|
|
3990
|
+
return;
|
|
3991
|
+
}
|
|
3992
|
+
var activeId = (activeTeamProfile && activeTeamProfile.profileId) || "";
|
|
3993
|
+
var locked = Boolean(activeTeamProfile && activeTeamProfile.transition);
|
|
3994
|
+
listEl.innerHTML = teamProfileRegistry.map(function (profile) {
|
|
3995
|
+
var isActive = profile.id === activeId;
|
|
3996
|
+
var pending = profileHasPendingSignoff(profile);
|
|
3997
|
+
var primary = currentLanguage === "zh"
|
|
3998
|
+
? (profile.nameZh || profile.name || profile.id)
|
|
3999
|
+
: (profile.name || profile.nameZh || profile.id);
|
|
4000
|
+
var secondary = currentLanguage === "zh"
|
|
4001
|
+
? (profile.name && profile.name !== primary ? profile.name : "")
|
|
4002
|
+
: (profile.nameZh && profile.nameZh !== primary ? profile.nameZh : "");
|
|
4003
|
+
return (
|
|
4004
|
+
'<button type="button" class="team-profile-card' + (isActive ? " active" : "") + (locked ? " is-locked" : "") +
|
|
4005
|
+
'" data-profile-id="' + escapeHtml(profile.id) + '"' + (isActive ? ' aria-current="true"' : "") + '>' +
|
|
4006
|
+
' <span class="team-profile-card-icon">' + escapeHtml(profile.icon || "") + "</span>" +
|
|
4007
|
+
' <span class="team-profile-card-main">' +
|
|
4008
|
+
' <span class="team-profile-card-name">' + escapeHtml(primary) +
|
|
4009
|
+
(secondary ? ' <span class="team-profile-card-name-alt">' + escapeHtml(secondary) + "</span>" : "") +
|
|
4010
|
+
(pending ? ' <span class="team-profile-chip pending" title="' + escapeHtml((profile.reviewedBy || []).join(" | ")) + '">' + escapeHtml(t("teamProfile.pendingSignoff")) + "</span>" : "") +
|
|
4011
|
+
"</span>" +
|
|
4012
|
+
' <span class="team-profile-card-desc">' + escapeHtml(profile.description || "") + "</span>" +
|
|
4013
|
+
' <span class="team-profile-card-meta">' +
|
|
4014
|
+
' <span class="team-profile-chip">' + escapeHtml(profile.industry || "") + "</span>" +
|
|
4015
|
+
' <span class="team-profile-chip">v' + escapeHtml(profile.version || "") + "</span>" +
|
|
4016
|
+
' <span class="team-profile-chip">' + escapeHtml(t("teamProfile.roleCount", { n: profile.roleCount || 0 })) + "</span>" +
|
|
4017
|
+
" </span>" +
|
|
4018
|
+
" </span>" +
|
|
4019
|
+
(isActive ? '<span class="team-profile-card-current">' + escapeHtml(t("teamProfile.current")) + "</span>" : "") +
|
|
4020
|
+
"</button>"
|
|
4021
|
+
);
|
|
4022
|
+
}).join("");
|
|
4023
|
+
}
|
|
4024
|
+
|
|
4025
|
+
function showTeamProfileListStep() {
|
|
4026
|
+
var listEl = $("#team-profile-list");
|
|
4027
|
+
var confirmEl = $("#team-profile-confirm");
|
|
4028
|
+
var statusEl = $("#team-profile-switch-status");
|
|
4029
|
+
if (!teamProfileSwitchInFlight) {
|
|
4030
|
+
pendingSwitchTarget = null;
|
|
4031
|
+
pendingSwitchProfileId = "";
|
|
4032
|
+
if (listEl) listEl.hidden = false;
|
|
4033
|
+
if (confirmEl) confirmEl.hidden = true;
|
|
4034
|
+
if (statusEl) statusEl.hidden = true;
|
|
4035
|
+
resetTeamProfileConfirmButton();
|
|
4036
|
+
renderTeamProfileCards();
|
|
4037
|
+
} else {
|
|
4038
|
+
// Keep the confirm step visible while the switch runs.
|
|
4039
|
+
if (listEl) listEl.hidden = true;
|
|
4040
|
+
if (confirmEl) confirmEl.hidden = false;
|
|
4041
|
+
}
|
|
4042
|
+
}
|
|
4043
|
+
|
|
4044
|
+
// Capability off->on restart semantics (#193): runtime teardown during a
|
|
4045
|
+
// switch is one-directional - switching a capability OFF stops its
|
|
4046
|
+
// subsystem immediately, but switching it back ON does not (re)start it
|
|
4047
|
+
// (TeamAuto scheduling / preview restoration are wired at controller
|
|
4048
|
+
// startup only). Any capability that DIFFERS between the active profile
|
|
4049
|
+
// and the selected target therefore deserves a heads-up in the confirm
|
|
4050
|
+
// step. Data: the active profile's capabilities from /team/profile, the
|
|
4051
|
+
// target's from the /profiles listing. Older controllers without the
|
|
4052
|
+
// capabilities field simply skip the hint.
|
|
4053
|
+
function teamProfileCapabilitiesChanging(targetProfile) {
|
|
4054
|
+
var activeCaps = activeTeamProfile && activeTeamProfile.profile && activeTeamProfile.profile.capabilities;
|
|
4055
|
+
var targetCaps = targetProfile && targetProfile.capabilities;
|
|
4056
|
+
if (!activeCaps || !targetCaps) return [];
|
|
4057
|
+
return Object.keys(targetCaps).filter(function (key) {
|
|
4058
|
+
return Boolean(activeCaps[key]) !== Boolean(targetCaps[key]);
|
|
4059
|
+
});
|
|
4060
|
+
}
|
|
4061
|
+
|
|
4062
|
+
function showTeamProfileConfirmStep(profile) {
|
|
4063
|
+
if (!profile) return;
|
|
4064
|
+
var listEl = $("#team-profile-list");
|
|
4065
|
+
var confirmEl = $("#team-profile-confirm");
|
|
4066
|
+
var bodyEl = $("#team-profile-confirm-body");
|
|
4067
|
+
var statusEl = $("#team-profile-switch-status");
|
|
4068
|
+
pendingSwitchTarget = profile;
|
|
4069
|
+
pendingSwitchProfileId = profile.id;
|
|
4070
|
+
if (listEl) listEl.hidden = true;
|
|
4071
|
+
if (confirmEl) confirmEl.hidden = false;
|
|
4072
|
+
if (statusEl) statusEl.hidden = true;
|
|
4073
|
+
var taskCount = (teamState.tasks || []).length;
|
|
4074
|
+
var changingCaps = teamProfileCapabilitiesChanging(profile);
|
|
4075
|
+
if (bodyEl) {
|
|
4076
|
+
bodyEl.innerHTML = (
|
|
4077
|
+
"<h3>" + escapeHtml((profile.icon ? profile.icon + " " : "") + profileDisplayLabel(profile)) + "</h3>" +
|
|
4078
|
+
'<p class="team-profile-confirm-warning">' + escapeHtml(t("teamProfile.confirmArchive", { n: taskCount })) + "</p>" +
|
|
4079
|
+
'<p class="workspace-prompt-note">' + escapeHtml(t("teamProfile.confirmWorkers")) + "</p>" +
|
|
4080
|
+
(changingCaps.length
|
|
4081
|
+
? '<p class="team-profile-confirm-warning">' +
|
|
4082
|
+
escapeHtml(t("teamProfile.capabilityRestartHint", { list: changingCaps.join(", ") })) +
|
|
4083
|
+
"</p>"
|
|
4084
|
+
: "")
|
|
4085
|
+
);
|
|
4086
|
+
}
|
|
4087
|
+
resetTeamProfileConfirmButton();
|
|
4088
|
+
}
|
|
4089
|
+
|
|
4090
|
+
function resetTeamProfileConfirmButton() {
|
|
4091
|
+
var button = $("#team-profile-confirm-btn");
|
|
4092
|
+
if (!button) return;
|
|
4093
|
+
button.disabled = false;
|
|
4094
|
+
button.textContent = t("teamProfile.confirmButton");
|
|
4095
|
+
}
|
|
4096
|
+
|
|
4097
|
+
// POST /team/profile resolves 202 immediately; progress arrives through
|
|
4098
|
+
// the WS events, so this fetch is separate from apiRequest to read the
|
|
4099
|
+
// 409 (transition in progress) status and body directly.
|
|
4100
|
+
function submitTeamProfileSwitch(profileId) {
|
|
4101
|
+
var button = $("#team-profile-confirm-btn");
|
|
4102
|
+
var statusEl = $("#team-profile-switch-status");
|
|
4103
|
+
if (!profileId) return;
|
|
4104
|
+
if (button) {
|
|
4105
|
+
button.disabled = true;
|
|
4106
|
+
button.textContent = t("teamProfile.switching");
|
|
4107
|
+
}
|
|
4108
|
+
if (statusEl) {
|
|
4109
|
+
statusEl.hidden = false;
|
|
4110
|
+
statusEl.textContent = t("teamProfile.switchStarted");
|
|
4111
|
+
}
|
|
4112
|
+
teamProfileSwitchInFlight = true;
|
|
4113
|
+
pendingSwitchProfileId = profileId;
|
|
4114
|
+
fetch(API_BASE + "/team/profile", {
|
|
4115
|
+
method: "POST",
|
|
4116
|
+
headers: { "Content-Type": "application/json" },
|
|
4117
|
+
body: JSON.stringify({ profileId: profileId }),
|
|
4118
|
+
}).then(function (res) {
|
|
4119
|
+
return res.json().catch(function () { return {}; }).then(function (data) {
|
|
4120
|
+
return { status: res.status, ok: res.ok, data: data };
|
|
4121
|
+
});
|
|
4122
|
+
}).then(function (result) {
|
|
4123
|
+
if (result.status === 202) {
|
|
4124
|
+
// Progress + completion arrive via team.switch_started /
|
|
4125
|
+
// team.switch_completed; reconcileTeamProfileSwitch covers a lost
|
|
4126
|
+
// WS connection on every refreshAll.
|
|
4127
|
+
renderTeamProfileTransitionNotice({ phase: "draining", targetProfileId: profileId });
|
|
4128
|
+
return;
|
|
4129
|
+
}
|
|
4130
|
+
if (result.status === 409) {
|
|
4131
|
+
var transition = (result.data && result.data.transition) ||
|
|
4132
|
+
(activeTeamProfile && activeTeamProfile.transition) || null;
|
|
4133
|
+
renderTeamProfileTransitionNotice(transition, result.data && result.data.error);
|
|
4134
|
+
releaseTeamProfileSwitchUi();
|
|
4135
|
+
return;
|
|
4136
|
+
}
|
|
4137
|
+
throw new Error((result.data && (result.data.error || result.data.message)) || ("Request failed: " + result.status));
|
|
4138
|
+
}).catch(function (err) {
|
|
4139
|
+
showError(err instanceof Error ? err.message : "Failed to switch team profile");
|
|
4140
|
+
releaseTeamProfileSwitchUi();
|
|
4141
|
+
});
|
|
4142
|
+
}
|
|
4143
|
+
|
|
4144
|
+
function releaseTeamProfileSwitchUi() {
|
|
4145
|
+
teamProfileSwitchInFlight = false;
|
|
4146
|
+
pendingSwitchProfileId = "";
|
|
4147
|
+
resetTeamProfileConfirmButton();
|
|
4148
|
+
var statusEl = $("#team-profile-switch-status");
|
|
4149
|
+
if (statusEl) statusEl.hidden = true;
|
|
4150
|
+
}
|
|
4151
|
+
|
|
4152
|
+
function finishTeamProfileSwitch(completedProfileId) {
|
|
4153
|
+
var targetId = completedProfileId || pendingSwitchProfileId || "";
|
|
4154
|
+
releaseTeamProfileSwitchUi();
|
|
4155
|
+
pendingSwitchTarget = null;
|
|
4156
|
+
closeTeamProfileModal();
|
|
4157
|
+
showTeamProfileListStep();
|
|
4158
|
+
showNotice(
|
|
4159
|
+
"team:switch_completed",
|
|
4160
|
+
"success",
|
|
4161
|
+
t("teamProfile.switchCompleted", { name: teamProfileDisplayNameById(targetId) }),
|
|
4162
|
+
"",
|
|
4163
|
+
);
|
|
4164
|
+
}
|
|
4165
|
+
|
|
4166
|
+
// Called from refreshAll: if a switch this UI initiated is no longer in a
|
|
4167
|
+
// transition, it either completed (profileId moved to the target - close
|
|
4168
|
+
// the modal) or aborted (re-enable the button).
|
|
4169
|
+
function reconcileTeamProfileSwitch() {
|
|
4170
|
+
if (!pendingSwitchProfileId && !teamProfileSwitchInFlight) return;
|
|
4171
|
+
if (activeTeamProfile.transition) {
|
|
4172
|
+
renderTeamProfileTransitionNotice(activeTeamProfile.transition);
|
|
4173
|
+
return;
|
|
4174
|
+
}
|
|
4175
|
+
if (activeTeamProfile.profileId === pendingSwitchProfileId) {
|
|
4176
|
+
finishTeamProfileSwitch(activeTeamProfile.profileId);
|
|
4177
|
+
} else {
|
|
4178
|
+
releaseTeamProfileSwitchUi();
|
|
4179
|
+
}
|
|
4180
|
+
}
|
|
4181
|
+
|
|
4182
|
+
function renderTeamProfileTransitionNotice(transition, errorText) {
|
|
4183
|
+
var el = $("#team-profile-transition");
|
|
4184
|
+
if (!el) return;
|
|
4185
|
+
var tr = transition || (activeTeamProfile && activeTeamProfile.transition) || null;
|
|
4186
|
+
if (!tr) {
|
|
4187
|
+
el.hidden = true;
|
|
4188
|
+
el.textContent = "";
|
|
4189
|
+
return;
|
|
4190
|
+
}
|
|
4191
|
+
el.hidden = false;
|
|
4192
|
+
el.textContent = t("teamProfile.transitionPending", {
|
|
4193
|
+
name: teamProfileDisplayNameById(tr.targetProfileId),
|
|
4194
|
+
phase: tr.phase || "",
|
|
4195
|
+
}) + (errorText ? " - " + errorText : "");
|
|
4196
|
+
}
|
|
4197
|
+
|
|
4198
|
+
function renderTeamProfileArchives() {
|
|
4199
|
+
var el = $("#team-profile-archives");
|
|
4200
|
+
if (!el) return;
|
|
4201
|
+
apiGet("/archived-teams").then(function (data) {
|
|
4202
|
+
var archives = data && Array.isArray(data.archives) ? data.archives : [];
|
|
4203
|
+
if (!archives.length) {
|
|
4204
|
+
el.innerHTML = '<div class="empty-state">' + escapeHtml(t("teamProfile.archivedEmpty")) + "</div>";
|
|
4205
|
+
return;
|
|
4206
|
+
}
|
|
4207
|
+
el.innerHTML = archives.map(function (archive) {
|
|
4208
|
+
var when = archive.archivedAt ? new Date(archive.archivedAt).toLocaleString() : "";
|
|
4209
|
+
return (
|
|
4210
|
+
'<div class="team-profile-archive-row">' +
|
|
4211
|
+
'<span class="team-profile-archive-team">' + escapeHtml(archive.teamName || archive.profileName || archive.profileId || "") + "</span>" +
|
|
4212
|
+
'<span class="team-profile-archive-profile">' + escapeHtml(archive.profileName || archive.profileId || "") + "</span>" +
|
|
4213
|
+
'<span class="team-profile-archive-meta">' + escapeHtml(when) + " · " + escapeHtml(t("teamProfile.archivedTasks", { n: archive.taskCount || 0 })) + "</span>" +
|
|
4214
|
+
"</div>"
|
|
4215
|
+
);
|
|
4216
|
+
}).join("");
|
|
4217
|
+
}).catch(function () {
|
|
4218
|
+
el.innerHTML = '<div class="empty-state">' + escapeHtml(t("teamProfile.archivedEmpty")) + "</div>";
|
|
4219
|
+
});
|
|
4220
|
+
}
|
|
4221
|
+
|
|
4222
|
+
function bindTeamProfileModal() {
|
|
4223
|
+
var toggle = $("#team-profile-toggle");
|
|
4224
|
+
if (toggle && !toggle.dataset.bound) {
|
|
4225
|
+
toggle.dataset.bound = "true";
|
|
4226
|
+
toggle.addEventListener("click", openTeamProfileModal);
|
|
4227
|
+
}
|
|
4228
|
+
var modal = $("#team-profile-modal");
|
|
4229
|
+
if (!modal || modal.dataset.bound === "true") return;
|
|
4230
|
+
modal.dataset.bound = "true";
|
|
4231
|
+
|
|
4232
|
+
modal.addEventListener("click", function (event) {
|
|
4233
|
+
if (event.target && event.target.hasAttribute && event.target.hasAttribute("data-team-profile-close")) {
|
|
4234
|
+
closeTeamProfileModal();
|
|
4235
|
+
}
|
|
4236
|
+
});
|
|
4237
|
+
|
|
4238
|
+
var listEl = $("#team-profile-list");
|
|
4239
|
+
if (listEl) {
|
|
4240
|
+
listEl.addEventListener("click", function (event) {
|
|
4241
|
+
var card = event.target instanceof Element ? event.target.closest("[data-profile-id]") : null;
|
|
4242
|
+
if (!card) return;
|
|
4243
|
+
var profileId = card.getAttribute("data-profile-id") || "";
|
|
4244
|
+
var profile = teamProfileRegistry.filter(function (p) { return p.id === profileId; })[0];
|
|
4245
|
+
if (!profile) return;
|
|
4246
|
+
var activeId = (activeTeamProfile && activeTeamProfile.profileId) || "";
|
|
4247
|
+
if (profileId === activeId) return; // current team: informational only
|
|
4248
|
+
if (activeTeamProfile && activeTeamProfile.transition) {
|
|
4249
|
+
// A switch is already running (section 2.3 409 matrix): surface
|
|
4250
|
+
// the in-progress notice instead of a second confirmation.
|
|
4251
|
+
renderTeamProfileTransitionNotice(activeTeamProfile.transition);
|
|
4252
|
+
return;
|
|
4253
|
+
}
|
|
4254
|
+
showTeamProfileConfirmStep(profile);
|
|
4255
|
+
});
|
|
4256
|
+
}
|
|
4257
|
+
|
|
4258
|
+
var backButton = $("#team-profile-confirm-back");
|
|
4259
|
+
if (backButton) {
|
|
4260
|
+
backButton.addEventListener("click", function () {
|
|
4261
|
+
if (teamProfileSwitchInFlight) return; // switch already submitted
|
|
4262
|
+
showTeamProfileListStep();
|
|
4263
|
+
});
|
|
4264
|
+
}
|
|
4265
|
+
|
|
4266
|
+
var confirmButton = $("#team-profile-confirm-btn");
|
|
4267
|
+
if (confirmButton) {
|
|
4268
|
+
confirmButton.addEventListener("click", function () {
|
|
4269
|
+
if (!pendingSwitchTarget || teamProfileSwitchInFlight) return;
|
|
4270
|
+
submitTeamProfileSwitch(pendingSwitchTarget.id);
|
|
4271
|
+
});
|
|
4272
|
+
}
|
|
4273
|
+
}
|
|
4274
|
+
|
|
3707
4275
|
function bindModelSettings() {
|
|
3708
4276
|
/* Module-level IIFE helper: delegated here to keep startup order simple. */
|
|
3709
4277
|
var opener = document.createElement("button");
|