dsh-cohub 0.13.2 → 0.13.4

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/lib/client.js CHANGED
@@ -70,6 +70,12 @@ window.__ModuleLoader__.load({
70
70
  "co-cordis"
71
71
  ];
72
72
 
73
+ /** Config.customRoles[].tier 的五个合法档位(自定义角色不得越权,取值与 Config schema 一致)。 */
74
+ var ROLE_TIERS = ["ro", "ro-net", "rw", "rw-shell", "cordis"];
75
+
76
+ /** 自定义角色名必须是 kebab-case:运行时把它注册成 skill 名,含空格/大写会污染技能表。 */
77
+ var ROLE_NAME_PATTERN = /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/;
78
+
73
79
  var zh = {
74
80
  nav: "CoHub 代理",
75
81
  title: "CoHub 代理模型",
@@ -114,7 +120,27 @@ window.__ModuleLoader__.load({
114
120
  "skill.co-rule-user": "用户规则",
115
121
  "skill.co-rule-project": "项目规则",
116
122
  "skill.co-rule-app": "应用规则",
117
- "skill.co-cordis": "Cordis 插件"
123
+ "skill.co-cordis": "Cordis 插件",
124
+ rolesTitle: "自定义团队",
125
+ rolesDescription: "在此增删改自定义角色。保存后运行时注册器约 1 秒内热加载,无需重启。",
126
+ roleName: "名称",
127
+ roleDescription: "描述",
128
+ rolePrompt: "提示词",
129
+ roleTier: "权限档位",
130
+ roleAdd: "添加角色",
131
+ roleRemove: "删除",
132
+ roleEmpty: "还没有自定义角色,点「添加角色」开始。",
133
+ roleSaved: "已保存,约 1 秒后生效,无需重启。",
134
+ roleDirty: "有未保存的修改。",
135
+ roleSavedLabel: "保存",
136
+ roleUnsaved: "未命名角色",
137
+ roleErrSummary: "有 {count} 处不合法,已标红,未保存。",
138
+ roleErrNameRequired: "名称必填。",
139
+ roleErrNameFormat: "名称须为 kebab-case(小写字母/数字,用 - 连接)。",
140
+ roleErrNameBuiltin: "名称与内置角色重名。",
141
+ roleErrNameDuplicate: "名称与其他自定义角色重复。",
142
+ roleErrDescription: "描述不能为空。",
143
+ roleErrPrompt: "提示词不能为空。"
118
144
  };
119
145
 
120
146
  var en = {
@@ -161,7 +187,27 @@ window.__ModuleLoader__.load({
161
187
  "skill.co-rule-user": "User rules",
162
188
  "skill.co-rule-project": "Project rules",
163
189
  "skill.co-rule-app": "App rules",
164
- "skill.co-cordis": "Cordis plugins"
190
+ "skill.co-cordis": "Cordis plugins",
191
+ rolesTitle: "Custom team",
192
+ rolesDescription: "Add, edit or remove custom roles here. The runtime registrar picks changes up in about 1 second — no restart needed.",
193
+ roleName: "Name",
194
+ roleDescription: "Description",
195
+ rolePrompt: "Prompt",
196
+ roleTier: "Access tier",
197
+ roleAdd: "Add role",
198
+ roleRemove: "Remove",
199
+ roleEmpty: "No custom roles yet. Click \"Add role\" to start.",
200
+ roleSaved: "Saved. Takes effect in about 1 second — no restart needed.",
201
+ roleDirty: "Unsaved changes.",
202
+ roleSavedLabel: "Save",
203
+ roleUnsaved: "Unnamed role",
204
+ roleErrSummary: "{count} invalid field(s), highlighted in red. Nothing was saved.",
205
+ roleErrNameRequired: "Name is required.",
206
+ roleErrNameFormat: "Name must be kebab-case (lowercase letters/digits joined by -).",
207
+ roleErrNameBuiltin: "Name collides with a built-in role.",
208
+ roleErrNameDuplicate: "Name duplicates another custom role.",
209
+ roleErrDescription: "Description is required.",
210
+ roleErrPrompt: "Prompt is required."
165
211
  };
166
212
 
167
213
  /** 无 locale 服务时的最小翻译(防止 props.t 缺失导致页面白屏)。 */
@@ -326,6 +372,92 @@ window.__ModuleLoader__.load({
326
372
  return rows;
327
373
  }
328
374
 
375
+ /* ── 纯数据层:Config.customRoles ↔ 编辑行 ────────────────────── */
376
+
377
+ function emptyRole() {
378
+ return { name: "", description: "", prompt: "", tier: "ro" };
379
+ }
380
+
381
+ function copyRole(role) {
382
+ return {
383
+ name: typeof role.name === "string" ? role.name : "",
384
+ description: typeof role.description === "string" ? role.description : "",
385
+ prompt: typeof role.prompt === "string" ? role.prompt : "",
386
+ tier: ROLE_TIERS.indexOf(role.tier) >= 0 ? role.tier : "ro"
387
+ };
388
+ }
389
+
390
+ /**
391
+ * Config.customRoles → 编辑行。
392
+ * 老配置没有该字段(undefined)时返回空数组,页面按「还没有自定义角色」展示。
393
+ * @param roles - configForms 快照里的 value.customRoles(任意形状,逐项校验)。
394
+ * @returns 编辑行数组。
395
+ */
396
+ function rowsFromCustomRoles(roles) {
397
+ var rows = [];
398
+ if (!Array.isArray(roles)) return rows;
399
+ for (var i = 0; i < roles.length; i += 1) {
400
+ var entry = roles[i];
401
+ if (!entry || typeof entry !== "object") continue;
402
+ rows.push(copyRole(entry));
403
+ }
404
+ return rows;
405
+ }
406
+
407
+ /** 编辑行 → 待写入的 customRoles 数组(只写四个受控字段,tier 越界退回 ro)。 */
408
+ function rolesToCustomRoles(rows) {
409
+ var out = [];
410
+ if (!Array.isArray(rows)) return out;
411
+ for (var i = 0; i < rows.length; i += 1) {
412
+ var role = rows[i];
413
+ if (!role || typeof role !== "object") continue;
414
+ out.push(copyRole(role));
415
+ }
416
+ return out;
417
+ }
418
+
419
+ /**
420
+ * 提交前的前端校验:违反任一条就不写配置(写进去会污染技能表或让子代理拿错档位)。
421
+ * 规则:name 必填 + kebab-case + 不撞内置 SKILL_NAMES + 表内不重名;description / prompt 非空。
422
+ * @returns 与 rows 等长的错误数组,空串表示该字段合法。
423
+ */
424
+ function validateRoles(rows) {
425
+ var errors = [];
426
+ var counts = {};
427
+ var list = Array.isArray(rows) ? rows : [];
428
+ var i;
429
+ for (i = 0; i < list.length; i += 1) {
430
+ var name = list[i] && typeof list[i].name === "string" ? list[i].name : "";
431
+ if (name === "") continue;
432
+ counts[name] = (counts[name] || 0) + 1;
433
+ }
434
+ for (i = 0; i < list.length; i += 1) {
435
+ var role = list[i] || {};
436
+ var raw = typeof role.name === "string" ? role.name : "";
437
+ var error = { name: "", description: "", prompt: "" };
438
+ if (raw === "") error.name = "nameRequired";
439
+ else if (!ROLE_NAME_PATTERN.test(raw)) error.name = "nameFormat";
440
+ else if (SKILL_NAMES.indexOf(raw) >= 0) error.name = "nameBuiltin";
441
+ else if (counts[raw] > 1) error.name = "nameDuplicate";
442
+ if (typeof role.description !== "string" || role.description.trim() === "") error.description = "required";
443
+ if (typeof role.prompt !== "string" || role.prompt.trim() === "") error.prompt = "required";
444
+ errors.push(error);
445
+ }
446
+ return errors;
447
+ }
448
+
449
+ /** 错误表里被标红的字段数(0 = 可以提交)。 */
450
+ function countRoleErrors(errors) {
451
+ var count = 0;
452
+ for (var i = 0; i < errors.length; i += 1) {
453
+ var error = errors[i] || {};
454
+ if (error.name !== "") count += 1;
455
+ if (error.description !== "") count += 1;
456
+ if (error.prompt !== "") count += 1;
457
+ }
458
+ return count;
459
+ }
460
+
329
461
  /* ── 极简 observable store(uSES:快照未变必须返回同一引用) ──── */
330
462
 
331
463
  function createStateStore(initial) {
@@ -371,7 +503,12 @@ window.__ModuleLoader__.load({
371
503
  // effortsByModel[provider][modelId] = [{ id, label }];模型不支持推理强度时该键缺失。
372
504
  effortsByModel: {},
373
505
  catalogStatus: "loading",
374
- catalogError: ""
506
+ catalogError: "",
507
+ roles: [],
508
+ rolesDirty: false,
509
+ rolesSaved: false,
510
+ rolesFailed: false,
511
+ roleErrors: []
375
512
  });
376
513
 
377
514
  /**
@@ -400,8 +537,16 @@ window.__ModuleLoader__.load({
400
537
 
401
538
  var lastValue;
402
539
  var lastRows = [];
540
+ var lastRoles = [];
403
541
  var published = null;
404
542
 
543
+ // 自定义角色草稿与 skills 草稿各自独立(写的是不同 path),但共用同一 scope、
544
+ // 同一 revision 冲突判定和同一个 saving 互斥位。roleErrors 与行等长,空串 = 合法。
545
+ var rolesDraft = null; // { rows, revision }
546
+ var rolesSaved = false;
547
+ var rolesFailed = false;
548
+ var roleErrors = [];
549
+
405
550
  function readScope() {
406
551
  if (!scope || typeof scope.getSnapshot !== "function") {
407
552
  return { status: "unavailable", writable: false, value: undefined, revision: undefined };
@@ -414,15 +559,25 @@ window.__ModuleLoader__.load({
414
559
  }
415
560
  }
416
561
 
417
- function currentRows() {
562
+ /** 快照 value 变了一次就把 skills 与 customRoles 两份编辑行一起重算(共用同一引用判断)。 */
563
+ function refreshFromValue() {
418
564
  var snapshot = readScope();
419
- if (snapshot.value !== lastValue) {
420
- lastValue = snapshot.value;
421
- lastRows = displayRows(rowsFromSkills(snapshot.value && snapshot.value.skills));
422
- }
565
+ if (snapshot.value === lastValue) return;
566
+ lastValue = snapshot.value;
567
+ lastRows = displayRows(rowsFromSkills(snapshot.value && snapshot.value.skills));
568
+ lastRoles = rowsFromCustomRoles(snapshot.value && snapshot.value.customRoles);
569
+ }
570
+
571
+ function currentRows() {
572
+ refreshFromValue();
423
573
  return lastRows;
424
574
  }
425
575
 
576
+ function currentRoles() {
577
+ refreshFromValue();
578
+ return lastRoles;
579
+ }
580
+
426
581
  function buildState() {
427
582
  var snapshot = readScope();
428
583
  return {
@@ -438,7 +593,12 @@ window.__ModuleLoader__.load({
438
593
  modelsByProvider: catalogByProvider,
439
594
  effortsByModel: catalogEfforts,
440
595
  catalogStatus: catalogStatus,
441
- catalogError: catalogError
596
+ catalogError: catalogError,
597
+ roles: rolesDraft !== null ? rolesDraft.rows : currentRoles(),
598
+ rolesDirty: rolesDraft !== null,
599
+ rolesSaved: rolesSaved,
600
+ rolesFailed: rolesFailed,
601
+ roleErrors: roleErrors
442
602
  };
443
603
  }
444
604
 
@@ -456,7 +616,12 @@ window.__ModuleLoader__.load({
456
616
  && left.modelsByProvider === right.modelsByProvider
457
617
  && left.effortsByModel === right.effortsByModel
458
618
  && left.catalogStatus === right.catalogStatus
459
- && left.catalogError === right.catalogError;
619
+ && left.catalogError === right.catalogError
620
+ && left.roles === right.roles
621
+ && left.rolesDirty === right.rolesDirty
622
+ && left.rolesSaved === right.rolesSaved
623
+ && left.rolesFailed === right.rolesFailed
624
+ && left.roleErrors === right.roleErrors;
460
625
  }
461
626
 
462
627
  function publish() {
@@ -470,9 +635,10 @@ window.__ModuleLoader__.load({
470
635
  function onScopeChange() {
471
636
  if (disposed) return;
472
637
  // 自己的写入进行中不做冲突判定:revision 变化正是本次写入引起的。
473
- if (!saving && draft !== null) {
638
+ if (!saving && (draft !== null || rolesDraft !== null)) {
474
639
  var snapshot = readScope();
475
- if (snapshot.revision !== draft.revision) conflicted = true;
640
+ if (draft !== null && snapshot.revision !== draft.revision) conflicted = true;
641
+ if (rolesDraft !== null && snapshot.revision !== rolesDraft.revision) conflicted = true;
476
642
  }
477
643
  publish();
478
644
  }
@@ -487,6 +653,16 @@ window.__ModuleLoader__.load({
487
653
  return draft;
488
654
  }
489
655
 
656
+ function beginRolesDraft() {
657
+ if (rolesDraft !== null) return rolesDraft;
658
+ var snapshot = readScope();
659
+ var source = currentRoles();
660
+ var rows = [];
661
+ for (var i = 0; i < source.length; i += 1) rows.push(copyRole(source[i]));
662
+ rolesDraft = { rows: rows, revision: snapshot.revision };
663
+ return rolesDraft;
664
+ }
665
+
490
666
  function canEdit() {
491
667
  if (disposed || saving || conflicted) return false;
492
668
  var snapshot = readScope();
@@ -667,6 +843,127 @@ window.__ModuleLoader__.load({
667
843
  });
668
844
  }
669
845
 
846
+ /**
847
+ * 改一行的某个字段(name / description / prompt / tier)。
848
+ * 只写受控四字段,避免把 Config 里别的键带歪;提交过校验后改字段会即时重算标红。
849
+ */
850
+ function editRole(index, field, value) {
851
+ if (field !== "name" && field !== "description" && field !== "prompt" && field !== "tier") return;
852
+ if (!canEdit()) return;
853
+ var current = beginRolesDraft();
854
+ if (index < 0 || index >= current.rows.length) return;
855
+ if (current.rows[index][field] === value) return;
856
+ var next = [];
857
+ for (var i = 0; i < current.rows.length; i += 1) {
858
+ var copy = copyRole(current.rows[i]);
859
+ if (i === index) copy[field] = value;
860
+ next.push(copy);
861
+ }
862
+ rolesDraft.rows = next;
863
+ roleErrors = roleErrors.length > 0 ? validateRoles(next) : [];
864
+ rolesSaved = false;
865
+ rolesFailed = false;
866
+ publish();
867
+ }
868
+
869
+ /** 追加一个空行(默认 tier=ro,最小权限起步)。 */
870
+ function addRole() {
871
+ if (!canEdit()) return;
872
+ var current = beginRolesDraft();
873
+ var next = [];
874
+ for (var i = 0; i < current.rows.length; i += 1) next.push(copyRole(current.rows[i]));
875
+ next.push(emptyRole());
876
+ rolesDraft.rows = next;
877
+ roleErrors = [];
878
+ rolesSaved = false;
879
+ rolesFailed = false;
880
+ publish();
881
+ }
882
+
883
+ /** 删掉一行。删空后保存即写回 [],运行时注册器会移除这些角色。 */
884
+ function removeRole(index) {
885
+ if (!canEdit()) return;
886
+ var current = beginRolesDraft();
887
+ if (index < 0 || index >= current.rows.length) return;
888
+ var next = [];
889
+ for (var i = 0; i < current.rows.length; i += 1) {
890
+ if (i !== index) next.push(current.rows[i]);
891
+ }
892
+ rolesDraft.rows = next;
893
+ roleErrors = [];
894
+ rolesSaved = false;
895
+ rolesFailed = false;
896
+ publish();
897
+ }
898
+
899
+ function discardRoles() {
900
+ if (saving) return;
901
+ rolesDraft = null;
902
+ rolesSaved = false;
903
+ rolesFailed = false;
904
+ roleErrors = [];
905
+ publish();
906
+ }
907
+
908
+ /**
909
+ * 整表写回 Config.customRoles(数组字段整体替换,与 skills 同一 mutate 契约)。
910
+ * 校验不通过只标红、不发请求;成功后运行时注册器约 1 秒内热加载,无需重启。
911
+ */
912
+ function saveRoles() {
913
+ if (disposed || saving || rolesDraft === null) return Promise.resolve(false);
914
+ var snapshot = readScope();
915
+ if (snapshot.status !== "ready" || snapshot.writable !== true || conflicted) return Promise.resolve(false);
916
+ if (rolesDraft.revision !== undefined && snapshot.revision !== rolesDraft.revision) {
917
+ conflicted = true;
918
+ publish();
919
+ return Promise.resolve(false);
920
+ }
921
+ var errors = validateRoles(rolesDraft.rows);
922
+ if (countRoleErrors(errors) > 0) {
923
+ roleErrors = errors;
924
+ rolesSaved = false;
925
+ rolesFailed = false;
926
+ publish();
927
+ return Promise.resolve(false);
928
+ }
929
+ var expected = rolesDraft.revision;
930
+ var next = rolesToCustomRoles(rolesDraft.rows);
931
+ saving = true;
932
+ rolesSaved = false;
933
+ rolesFailed = false;
934
+ roleErrors = [];
935
+ publish();
936
+ var request;
937
+ try {
938
+ request = scope.mutate([{ op: "set", path: ["customRoles"], value: next }], expected);
939
+ } catch (error) {
940
+ saving = false;
941
+ rolesFailed = true;
942
+ publish();
943
+ return Promise.resolve(false);
944
+ }
945
+ return Promise.resolve(request).then(function (accepted) {
946
+ if (disposed) return false;
947
+ saving = false;
948
+ if (accepted === true) {
949
+ rolesDraft = null;
950
+ rolesFailed = false;
951
+ rolesSaved = true;
952
+ lastValue = undefined;
953
+ } else {
954
+ rolesFailed = true;
955
+ }
956
+ publish();
957
+ return accepted === true;
958
+ }, function () {
959
+ if (disposed) return false;
960
+ saving = false;
961
+ rolesFailed = true;
962
+ publish();
963
+ return false;
964
+ });
965
+ }
966
+
670
967
  function loadCatalog() {
671
968
  catalogGeneration += 1;
672
969
  var generation = catalogGeneration;
@@ -779,7 +1076,12 @@ window.__ModuleLoader__.load({
779
1076
  resetRow: resetRow,
780
1077
  discard: discard,
781
1078
  save: save,
782
- loadCatalog: loadCatalog
1079
+ loadCatalog: loadCatalog,
1080
+ editRole: editRole,
1081
+ addRole: addRole,
1082
+ removeRole: removeRole,
1083
+ discardRoles: discardRoles,
1084
+ saveRoles: saveRoles
783
1085
  };
784
1086
  }
785
1087
 
@@ -826,7 +1128,21 @@ window.__ModuleLoader__.load({
826
1128
  ".cohub-button-primary:hover:not(:disabled){background:var(--dsw-alias-button-primary-hover);}",
827
1129
  ".cohub-button-ghost{color:var(--dsw-alias-label-secondary);background:transparent;border:1px solid var(--dsw-alias-border-l2);}",
828
1130
  ".cohub-button-ghost:hover:not(:disabled){color:var(--dsw-alias-label-primary);}",
829
- ".cohub-button:disabled{opacity:.45;cursor:default;}"
1131
+ ".cohub-button:disabled{opacity:.45;cursor:default;}",
1132
+ // ── 自定义团队区块(与上面的模型区块隔开,各自独立的草稿与保存按钮) ──
1133
+ ".cohub-roles{display:flex;flex-direction:column;gap:12px;margin-top:8px;padding-top:16px;border-top:1px solid var(--dsw-alias-border-l2);}",
1134
+ ".cohub-subtitle{margin:0;font-size:14px;font-weight:600;line-height:22px;}",
1135
+ ".cohub-role-summary{flex:1 1 140px;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px;}",
1136
+ // 名称 + 档位并排,描述与提示词各自独占一行(prompt 是多行文本域,需要整行宽度)。
1137
+ ".cohub-role-fields{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,150px);gap:8px;margin-top:8px;align-items:start;}",
1138
+ "@media (max-width:560px){.cohub-role-fields{grid-template-columns:minmax(0,1fr);}}",
1139
+ ".cohub-field-wide{grid-column:1 / -1;}",
1140
+ ".cohub-textarea{box-sizing:border-box;width:100%;min-height:64px;resize:vertical;font:inherit;color:var(--dsw-alias-label-primary);background:var(--dsw-alias-bg-layer-3);border:1px solid var(--dsw-alias-border-l2);border-radius:8px;padding:6px 10px;font-size:13px;line-height:20px;}",
1141
+ ".cohub-textarea:focus-visible{border-color:var(--dsw-alias-brand-primary);outline:none;}",
1142
+ ".cohub-textarea:disabled{opacity:.6;cursor:default;}",
1143
+ // 校验失败的行:只把具体字段标红,行本身不整体变色。
1144
+ ".cohub-invalid{border-color:var(--dsw-alias-state-error-primary);}",
1145
+ ".cohub-role-error{margin:0;font-size:12px;line-height:18px;color:var(--dsw-alias-state-error-primary);}"
830
1146
  ].join("\n");
831
1147
  var tag = document.createElement("style");
832
1148
  tag.dataset.plugin = "dsh-cohub";
@@ -1037,6 +1353,170 @@ window.__ModuleLoader__.load({
1037
1353
  );
1038
1354
  }
1039
1355
 
1356
+ /* ── 自定义团队:增删改 Config.customRoles ─────────────────── */
1357
+
1358
+ var roles = state.roles || [];
1359
+ var roleErrors = state.roleErrors || [];
1360
+
1361
+ function roleErrorOf(index) {
1362
+ var error = roleErrors[index];
1363
+ return error && typeof error === "object" ? error : {};
1364
+ }
1365
+
1366
+ /** 把 validateRoles 的错误码翻成文案;一行可能同时命中多条(比如 name + prompt)。 */
1367
+ function roleMessage(error) {
1368
+ var parts = [];
1369
+ if (error.name === "nameRequired") parts.push(t("roleErrNameRequired"));
1370
+ else if (error.name === "nameFormat") parts.push(t("roleErrNameFormat"));
1371
+ else if (error.name === "nameBuiltin") parts.push(t("roleErrNameBuiltin"));
1372
+ else if (error.name === "nameDuplicate") parts.push(t("roleErrNameDuplicate"));
1373
+ if (error.description === "required") parts.push(t("roleErrDescription"));
1374
+ if (error.prompt === "required") parts.push(t("roleErrPrompt"));
1375
+ return parts.join(" ");
1376
+ }
1377
+
1378
+ function renderRole(role, index) {
1379
+ var error = roleErrorOf(index);
1380
+ var invalid = error.name !== "" || error.description !== "" || error.prompt !== "";
1381
+ var tierOptions = [];
1382
+ for (var k = 0; k < ROLE_TIERS.length; k += 1) {
1383
+ tierOptions.push(React.createElement("option", { key: ROLE_TIERS[k], value: ROLE_TIERS[k] }, ROLE_TIERS[k]));
1384
+ }
1385
+ var message = roleMessage(error);
1386
+ var typeLabel = role.name !== "" ? role.name : t("roleUnsaved");
1387
+ return React.createElement("li", {
1388
+ key: "role-" + index,
1389
+ className: invalid ? "cohub-row cohub-invalid" : "cohub-row"
1390
+ },
1391
+ React.createElement("div", { className: "cohub-row-head" },
1392
+ React.createElement("span", { className: "cohub-row-name" }, typeLabel),
1393
+ React.createElement("span", { className: "cohub-role-summary" },
1394
+ role.description !== "" ? role.description : t("roleDescription")),
1395
+ React.createElement("span", { className: "cohub-badge" }, role.tier),
1396
+ React.createElement("button", {
1397
+ type: "button",
1398
+ className: "cohub-row-reset",
1399
+ disabled: locked,
1400
+ "aria-label": t("roleRemove") + " " + typeLabel,
1401
+ onClick: function () {
1402
+ props.removeRole(index);
1403
+ }
1404
+ }, t("roleRemove"))
1405
+ ),
1406
+ React.createElement("div", { className: "cohub-role-fields" },
1407
+ React.createElement("div", { className: "cohub-field" },
1408
+ React.createElement("label", { className: "cohub-label" }, t("roleName")),
1409
+ React.createElement("input", {
1410
+ className: error.name !== "" ? "cohub-input cohub-invalid" : "cohub-input",
1411
+ type: "text",
1412
+ value: role.name,
1413
+ disabled: locked,
1414
+ placeholder: "my-reviewer",
1415
+ "aria-label": typeLabel + " · " + t("roleName"),
1416
+ onChange: function (event) {
1417
+ props.editRole(index, "name", event.target.value);
1418
+ }
1419
+ })
1420
+ ),
1421
+ React.createElement("div", { className: "cohub-field" },
1422
+ React.createElement("label", { className: "cohub-label" }, t("roleTier")),
1423
+ React.createElement("select", {
1424
+ className: "cohub-select",
1425
+ value: role.tier,
1426
+ disabled: locked,
1427
+ "aria-label": typeLabel + " · " + t("roleTier"),
1428
+ onChange: function (event) {
1429
+ props.editRole(index, "tier", event.target.value);
1430
+ }
1431
+ }, tierOptions)
1432
+ ),
1433
+ React.createElement("div", { className: "cohub-field cohub-field-wide" },
1434
+ React.createElement("label", { className: "cohub-label" }, t("roleDescription")),
1435
+ React.createElement("input", {
1436
+ className: error.description !== "" ? "cohub-input cohub-invalid" : "cohub-input",
1437
+ type: "text",
1438
+ value: role.description,
1439
+ disabled: locked,
1440
+ "aria-label": typeLabel + " · " + t("roleDescription"),
1441
+ onChange: function (event) {
1442
+ props.editRole(index, "description", event.target.value);
1443
+ }
1444
+ })
1445
+ ),
1446
+ React.createElement("div", { className: "cohub-field cohub-field-wide" },
1447
+ React.createElement("label", { className: "cohub-label" }, t("rolePrompt")),
1448
+ React.createElement("textarea", {
1449
+ className: error.prompt !== "" ? "cohub-textarea cohub-invalid" : "cohub-textarea",
1450
+ value: role.prompt,
1451
+ disabled: locked,
1452
+ rows: 3,
1453
+ "aria-label": typeLabel + " · " + t("rolePrompt"),
1454
+ onChange: function (event) {
1455
+ props.editRole(index, "prompt", event.target.value);
1456
+ }
1457
+ })
1458
+ )
1459
+ ),
1460
+ message !== "" ? React.createElement("p", { className: "cohub-role-error" }, message) : null
1461
+ );
1462
+ }
1463
+
1464
+ var roleItems = [];
1465
+ for (var r = 0; r < roles.length; r += 1) roleItems.push(renderRole(roles[r], r));
1466
+
1467
+ var roleErrorCount = countRoleErrors(roleErrors);
1468
+ var roleStatus = null;
1469
+ var roleStatusClass = "cohub-status";
1470
+ if (state.rolesFailed) {
1471
+ roleStatus = t("failed");
1472
+ roleStatusClass += " cohub-status-error";
1473
+ } else if (roleErrorCount > 0) {
1474
+ roleStatus = t("roleErrSummary", { count: roleErrorCount });
1475
+ roleStatusClass += " cohub-status-error";
1476
+ } else if (state.rolesSaved) {
1477
+ roleStatus = t("roleSaved");
1478
+ roleStatusClass += " cohub-status-ok";
1479
+ } else if (state.rolesDirty) {
1480
+ roleStatus = t("roleDirty");
1481
+ } else if (!state.writable) {
1482
+ roleStatus = t("readOnly");
1483
+ }
1484
+
1485
+ var rolesBlock = React.createElement("div", { className: "cohub-roles" },
1486
+ React.createElement("h3", { className: "cohub-subtitle" }, t("rolesTitle")),
1487
+ React.createElement("p", { className: "cohub-desc" }, t("rolesDescription")),
1488
+ roles.length === 0
1489
+ ? React.createElement("p", { className: "cohub-notice" }, t("roleEmpty"))
1490
+ : React.createElement("ul", { className: "cohub-rows" }, roleItems),
1491
+ React.createElement("div", { className: "cohub-actions" },
1492
+ React.createElement("button", {
1493
+ type: "button",
1494
+ className: "cohub-button cohub-button-ghost",
1495
+ disabled: locked,
1496
+ onClick: function () {
1497
+ props.addRole();
1498
+ }
1499
+ }, t("roleAdd")),
1500
+ roleStatus !== null ? React.createElement("p", { className: roleStatusClass }, roleStatus) : null,
1501
+ React.createElement("button", {
1502
+ type: "button",
1503
+ className: "cohub-button cohub-button-ghost",
1504
+ disabled: !state.rolesDirty || state.saving,
1505
+ onClick: function () {
1506
+ props.discardRoles();
1507
+ }
1508
+ }, t("discard")),
1509
+ React.createElement("button", {
1510
+ type: "button",
1511
+ className: "cohub-button cohub-button-primary",
1512
+ disabled: !state.rolesDirty || !state.writable || state.saving || state.conflicted,
1513
+ onClick: function () {
1514
+ props.saveRoles();
1515
+ }
1516
+ }, t(state.saving ? "saving" : "roleSavedLabel"))
1517
+ )
1518
+ );
1519
+
1040
1520
  var items = [];
1041
1521
  for (var i = 0; i < rows.length; i += 1) items.push(renderRow(rows[i]));
1042
1522
 
@@ -1094,7 +1574,8 @@ window.__ModuleLoader__.load({
1094
1574
  props.save();
1095
1575
  }
1096
1576
  }, t(state.saving ? "saving" : "save"))
1097
- )
1577
+ ),
1578
+ rolesBlock
1098
1579
  );
1099
1580
  }
1100
1581
 
@@ -1139,6 +1620,21 @@ window.__ModuleLoader__.load({
1139
1620
  },
1140
1621
  retryCatalog: function () {
1141
1622
  controller.loadCatalog();
1623
+ },
1624
+ editRole: function (index, field, value) {
1625
+ controller.editRole(index, field, value);
1626
+ },
1627
+ addRole: function () {
1628
+ controller.addRole();
1629
+ },
1630
+ removeRole: function (index) {
1631
+ controller.removeRole(index);
1632
+ },
1633
+ discardRoles: function () {
1634
+ controller.discardRoles();
1635
+ },
1636
+ saveRoles: function () {
1637
+ return controller.saveRoles();
1142
1638
  }
1143
1639
  };
1144
1640
  };