hiwork-core 0.0.21 → 0.0.24

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
@@ -142,7 +142,7 @@ function browserLoginViewOf(value) {
142
142
  if (loginMode === "form") return { loginMode, browserLoginUrl: void 0, browserLoginPending: false };
143
143
  return { loginMode, browserLoginUrl: authorizeUrlOf(value), browserLoginPending: browserLoginPendingOf(value) };
144
144
  }
145
- function openAuthorizeUrl(url) {
145
+ function openExternalUrl(url) {
146
146
  if (url === void 0 || url === "") return;
147
147
  if (typeof window === "undefined") return;
148
148
  let protocol;
@@ -154,6 +154,9 @@ function openAuthorizeUrl(url) {
154
154
  if (protocol !== "https:" && protocol !== "http:") return;
155
155
  window.open(url, "_blank", "noopener,noreferrer");
156
156
  }
157
+ function openAuthorizeUrl(url) {
158
+ openExternalUrl(url);
159
+ }
157
160
  async function requestBrowserLogin(scope) {
158
161
  await scope.set("browserLoginRequest", { at: (/* @__PURE__ */ new Date()).toISOString() });
159
162
  }
@@ -809,7 +812,7 @@ function LogoutIcon() {
809
812
  viewBox: "0 0 16 16",
810
813
  fill: "none",
811
814
  stroke: "currentColor",
812
- strokeWidth: 1.3,
815
+ strokeWidth: 1.25,
813
816
  strokeLinecap: "round",
814
817
  strokeLinejoin: "round",
815
818
  "aria-hidden": "true",
@@ -1318,6 +1321,64 @@ function removeStaleHeroGreeting(doc) {
1318
1321
  for (const stale of Array.from(doc.querySelectorAll("[data-hiwork-hero-greeting]"))) stale.remove();
1319
1322
  }
1320
1323
 
1324
+ // src/client/manual-link.ts
1325
+ var MANUAL_URL = "https://hiworkapp.hivery.cn/manual.html";
1326
+ var MANUAL_STYLE_ID = "hiwork-core-manual-style";
1327
+ var MANUAL_STYLE = `
1328
+ [data-hiwork-core-manual-entry]{box-sizing:border-box;flex:none;display:inline-flex;align-items:center;justify-content:center;width:28px;height:28px;margin-left:auto;padding:0;border:0;border-radius:999px;background:transparent;color:var(--dsw-alias-label-tertiary,#71717a);font-family:inherit;font-size:14px;line-height:1;font-weight:600;cursor:pointer;user-select:none;transition:background .16s ease,color .16s ease}
1329
+ [data-hiwork-core-manual-entry]:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(24,24,27,.06));color:var(--dsw-alias-label-secondary,#3f3f46)}
1330
+ [data-hiwork-core-manual-entry]:focus-visible{outline:2px solid var(--dsw-alias-button-info-fill,#4c8dff);outline-offset:2px}
1331
+ body[data-ds-dark-theme] [data-hiwork-core-manual-entry]{color:var(--dsw-alias-label-tertiary,#9ba3b4)}
1332
+ body[data-ds-dark-theme] [data-hiwork-core-manual-entry]:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.08));color:var(--dsw-alias-label-secondary,#a6adb8)}
1333
+ @media (prefers-reduced-motion: reduce){[data-hiwork-core-manual-entry]{transition:none}}
1334
+ `;
1335
+ function ensureManualStyle(doc) {
1336
+ if (doc.getElementById(MANUAL_STYLE_ID) !== null) return;
1337
+ if (doc.head === null) return;
1338
+ const style = doc.createElement("style");
1339
+ style.id = MANUAL_STYLE_ID;
1340
+ style.textContent = MANUAL_STYLE;
1341
+ doc.head.append(style);
1342
+ }
1343
+ function openManual() {
1344
+ openExternalUrl(MANUAL_URL);
1345
+ }
1346
+ function findManualMount(doc) {
1347
+ const hero = doc.querySelector('[data-phase="hero"]');
1348
+ if (hero === null) return null;
1349
+ return hero.querySelector('[class*="_heroWorkspaceRow"]');
1350
+ }
1351
+ function buildButton(doc) {
1352
+ const button = doc.createElement("button");
1353
+ button.dataset.hiworkCoreManualEntry = "";
1354
+ button.type = "button";
1355
+ button.title = "\u4F7F\u7528\u624B\u518C";
1356
+ button.setAttribute("aria-label", "\u4F7F\u7528\u624B\u518C");
1357
+ button.append(doc.createTextNode("?"));
1358
+ button.addEventListener("click", (event) => {
1359
+ event.preventDefault();
1360
+ event.stopPropagation();
1361
+ openManual();
1362
+ });
1363
+ return button;
1364
+ }
1365
+ function removeStaleManualEntry(doc) {
1366
+ for (const stale of Array.from(doc.querySelectorAll("[data-hiwork-core-manual-entry]"))) {
1367
+ stale.remove();
1368
+ }
1369
+ }
1370
+ function decorateManualEntry(doc) {
1371
+ const row = findManualMount(doc);
1372
+ if (row === null) {
1373
+ removeStaleManualEntry(doc);
1374
+ return;
1375
+ }
1376
+ const existing = row.querySelector(":scope > [data-hiwork-core-manual-entry]");
1377
+ if (existing !== null) return;
1378
+ removeStaleManualEntry(doc);
1379
+ row.append(buildButton(doc));
1380
+ }
1381
+
1321
1382
  // src/client/daily-card.ts
1322
1383
  var DAILY_CARD_STYLE_ID = "dcu-daily-card-style";
1323
1384
  var DAILY_MAIN_FONT_SIZE_MAX = 64;
@@ -1608,6 +1669,7 @@ function observeHeroDecorations(doc, quotes) {
1608
1669
  };
1609
1670
  ensureDailyCardStyle(doc);
1610
1671
  ensureHeroStyle(doc);
1672
+ ensureManualStyle(doc);
1611
1673
  let applying = false;
1612
1674
  let frame;
1613
1675
  let lastDailyDay = -1;
@@ -1620,6 +1682,7 @@ function observeHeroDecorations(doc, quotes) {
1620
1682
  if (today !== lastDailyDay) lastDailyDay = today;
1621
1683
  decorateDailyCard(doc, quotes);
1622
1684
  decorateHeroGreeting(doc);
1685
+ decorateManualEntry(doc);
1623
1686
  } finally {
1624
1687
  applying = false;
1625
1688
  }
@@ -1752,6 +1815,8 @@ var footStyle = { margin: "2px 0 0", fontSize: 11, color: INK_CAPTION, textAlign
1752
1815
  var browserHintStyle = { margin: 0, fontSize: 12, lineHeight: 1.6, color: INK_CAPTION, textAlign: "center" };
1753
1816
  var browserActionsStyle = { display: "flex", alignItems: "center", justifyContent: "center", gap: 18 };
1754
1817
  var toggleStyle = { ...linkButton, alignSelf: "center", fontSize: 12.5 };
1818
+ var footBlockStyle = { display: "flex", flexDirection: "column", alignItems: "center", gap: 4 };
1819
+ var manualLinkStyle = { ...linkButton, fontWeight: 500 };
1755
1820
  function describeLoginError(error) {
1756
1821
  if (error === void 0) return void 0;
1757
1822
  if (error.code === "GATEWAY_UNREACHABLE") return "\u7F51\u5173\u6682\u65F6\u4E0D\u53EF\u7528\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\uFF0C\u6216\u6539\u7528\u8D26\u53F7\u5BC6\u7801\u767B\u5F55";
@@ -1887,7 +1952,10 @@ function LoginGateModal(props) {
1887
1952
  browserLogin,
1888
1953
  form,
1889
1954
  showBrowserLogin && formVisible ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { "data-hiwork-core-secondary": true, "data-hiwork-core-form-collapse": true, type: "button", style: toggleStyle, onClick: () => setFormOpen(false), children: "\u6536\u8D77\u8D26\u53F7\u5BC6\u7801\u767B\u5F55" }) : null,
1890
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: footStyle, children: "\u4F01\u4E1A\u7EDF\u4E00\u8EAB\u4EFD\u8BA4\u8BC1 \xB7 LDAP" })
1955
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: footBlockStyle, children: [
1956
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: footStyle, children: "\u4F01\u4E1A\u7EDF\u4E00\u8EAB\u4EFD\u8BA4\u8BC1 \xB7 LDAP" }),
1957
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { "data-hiwork-core-secondary": true, "data-hiwork-core-manual-login": true, type: "button", style: manualLinkStyle, onClick: openManual, children: "\u4F7F\u7528\u624B\u518C" })
1958
+ ] })
1891
1959
  ] })
1892
1960
  ] })
1893
1961
  ] });
@@ -2696,8 +2764,8 @@ var DEFAULT_NEW_SESSION_LABEL = "\u65B0\u4F1A\u8BDD";
2696
2764
  var STYLE_ELEMENT_ID = "hiwork-feature-center-styles";
2697
2765
  var TOOLTIP_DELAY_MS = 500;
2698
2766
  var TOOLTIP_GAP_PX = 8;
2699
- var DEFAULT_NEW_SESSION_ICON = '<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M8 3.4v9.2M3.4 8h9.2" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"/></svg>';
2700
- var DEFAULT_FEATURE_ICON = '<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><rect x="2.75" y="2.75" width="10.5" height="10.5" rx="3" stroke="currentColor" stroke-width="1.5"/><circle cx="8" cy="8" r="1.4" fill="currentColor"/></svg>';
2767
+ var DEFAULT_NEW_SESSION_ICON = '<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M8.00003 0.3237C3.76075 0.3237 0.32373 3.76072 0.32373 8C0.32373 9.17603 0.589121 10.2922 1.0632 11.2901L1.35291 11.8989L2.5705 11.3205L2.28079 10.7117C1.89079 9.89074 1.67301 8.97167 1.67301 8C1.67301 4.50546 4.50549 1.67298 8.00003 1.67298C11.4946 1.67298 14.3271 4.50546 14.3271 8C14.3271 11.4945 11.4946 14.327 8.00003 14.327C7.28473 14.327 6.76077 14.277 6.29621 14.1487C5.83857 14.0224 5.40441 13.8109 4.88514 13.4488C4.12569 12.919 3.03778 12.7316 2.141 13.2978L2.12682 13.307L2.11264 13.3171L1.34886 13.854L1.79659 15.188L2.86122 14.4384C3.19068 14.2305 3.68325 14.2542 4.11326 14.5539C4.72789 14.9826 5.30042 15.2724 5.93762 15.4484C6.56803 15.6224 7.22776 15.6763 8.00003 15.6763C12.2393 15.6763 15.6763 12.2393 15.6763 8C15.6763 3.76072 12.2393 0.3237 8.00003 0.3237ZM7.32033 4.82535V7.32536H4.82538V8.67464H7.32033V11.1747H8.6696V8.67464H11.1747V7.32536H8.6696V4.82535H7.32033Z" fill="currentColor"></path></svg>';
2768
+ var DEFAULT_FEATURE_ICON = '<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M7.84457 5.06199C11.6605 4.93876 14.7962 6.14848 14.8484 7.76397C14.8875 8.97461 13.1838 10.0696 10.7215 10.5942" stroke="currentColor" stroke-width="1.2"></path><path d="M5.12742 8.07731C5.00419 4.26138 6.21391 1.12568 7.8294 1.07351C9.04004 1.03441 10.135 2.73808 10.6596 5.20037" stroke="currentColor" stroke-width="1.2"></path><path d="M8.02457 10.6802C4.20865 10.8034 1.07294 9.5937 1.02077 7.97821C0.981678 6.76758 2.68535 5.67262 5.14763 5.14798" stroke="currentColor" stroke-width="1.2"></path><path d="M10.7476 7.89535C10.8708 11.7113 9.66109 14.847 8.0456 14.8991C6.83496 14.9382 5.74 13.2346 5.21536 10.7723" stroke="currentColor" stroke-width="1.2"></path></svg>';
2701
2769
  var SESSION_ROW_SELECTOR = [
2702
2770
  '[class*="sessionRow"]',
2703
2771
  '[class*="projectRow"]',
@@ -3759,6 +3827,7 @@ var ManagedWorkbenchStore = class {
3759
3827
 
3760
3828
  // src/client/pms-todo.ts
3761
3829
  var PMS_TODO_CHANNEL = "/hiwork-pms-todo";
3830
+ var PMS_TODO_STATUS_REASONS = ["no-assignment", "gateway-signed-out", "unavailable"];
3762
3831
  var PmsTodoRpcError = class extends Error {
3763
3832
  constructor(code, message) {
3764
3833
  super(message);
@@ -3826,11 +3895,15 @@ function toStatus(value) {
3826
3895
  if (!isRecord3(value)) throw new PmsTodoRpcError(INTERNAL_CODE, INVALID_RESPONSE_MESSAGE4);
3827
3896
  const username = text5(value["username"]);
3828
3897
  const expiresAt = text5(value["expiresAt"]);
3898
+ const userId = value["userId"];
3899
+ const reason = value["reason"];
3829
3900
  return {
3830
3901
  configured: value["configured"] === true,
3831
3902
  loggedIn: value["loggedIn"] === true,
3832
3903
  ...username === void 0 ? {} : { username },
3833
- ...expiresAt === void 0 ? {} : { expiresAt }
3904
+ ...expiresAt === void 0 ? {} : { expiresAt },
3905
+ ...isInteger(userId) ? { userId } : {},
3906
+ ...typeof reason === "string" && PMS_TODO_STATUS_REASONS.includes(reason) ? { reason } : {}
3834
3907
  };
3835
3908
  }
3836
3909
  function toToday(value) {
@@ -3937,7 +4010,7 @@ var PmsTodoStore = class {
3937
4010
  /**
3938
4011
  * 在飞请求**连同它所属的世代与端点**一起记账。
3939
4012
  *
3940
- * 世代:`clear()`(登出 / 换账号)之后,账上那条是**上一个人**发起的,它的待办属于上一个人
4013
+ * 世代:`clear()`(换账号)之后,账上那条是**上一个人**发起的,它的待办属于上一个人
3941
4014
  * ——复用它等于让新账号看到上一个人的待办。端点:`today` 与 `statistics` 的返回值形状不同,
3942
4015
  * 只有同一个端点的并发调用才允许合并。
3943
4016
  */
@@ -3950,8 +4023,9 @@ var PmsTodoStore = class {
3950
4023
  * 本地镜像(同步)。从没同步过返回 `undefined`。
3951
4024
  *
3952
4025
  * ⚠️ 本方法有一次**惰性探测**:镜像还空着且从没探过时,它顺手发起一次 `status` 端点调用
3953
- * (结果到达后写镜像 + 通知订阅者)。理由——渲染是同步的,而「配没配凭据」只有主机知道;
3954
- * 没有这一步,`status` 端点就永远没有调用方,界面也只能靠一次失败的 `today()` 去反推。
4026
+ * (结果到达后写镜像 + 通知订阅者)。理由——渲染是同步的,而「网关里有没有 pms 分配、手上
4027
+ * 有没有令牌」只有主机知道;没有这一步,`status` 端点就永远没有调用方,界面也只能靠一次
4028
+ * 失败的 `today()` 去反推(而且那反推出来的原因往往正好是错的)。
3955
4029
  * 因此调用方看到 `undefined` **不是**「未配置」,而是「还不知道」:必须订阅。
3956
4030
  */
3957
4031
  status() {
@@ -3972,22 +4046,6 @@ var PmsTodoStore = class {
3972
4046
  const { value, generation } = await this.call("status", "status", {}, toStatus, signal);
3973
4047
  return this.adopt(value, generation);
3974
4048
  }
3975
- /**
3976
- * 登录(凭据交给 Host;**本层不留存密码、不写任何缓存**)。
3977
- *
3978
- * 成功时把返回的状态写进镜像——登录是「身份刚变过」,镜像必须跟着变。
3979
- */
3980
- async login(input) {
3981
- const payload = { username: input.username, password: input.password };
3982
- if (input.remember !== void 0) payload["remember"] = input.remember;
3983
- const { value, generation } = await this.call("login", "login", payload, toStatus);
3984
- return this.adopt(value, generation);
3985
- }
3986
- /** 登出(Host 侧清凭据);返回登出后的状态并写镜像。 */
3987
- async logout() {
3988
- const { value, generation } = await this.call("logout", "logout", {}, toStatus);
3989
- return this.adopt(value, generation);
3990
- }
3991
4049
  /**
3992
4050
  * 今日待办。
3993
4051
  *
@@ -4016,7 +4074,7 @@ var PmsTodoStore = class {
4016
4074
  /**
4017
4075
  * **我的未完成项目任务**(spec §3 D7):`myTasks` 端点的取数。
4018
4076
  *
4019
- * 入参是**空对象**,没有 `userId`——「谁的任务」由 Host 从凭据记录里取(客户端连自己的
4077
+ * 入参是**空对象**,没有 `userId`——「谁的任务」由 Host 从 mint 响应里取(客户端连自己的
4020
4078
  * PMS userId 都拿不到,这是 §3 D6 形状的一部分)。
4021
4079
  *
4022
4080
  * 与 `today` 同款:**不做本地缓存**(返回刚拉到的那一份),但**并发调用合并**(同一时刻问两遍
@@ -4049,7 +4107,8 @@ var PmsTodoStore = class {
4049
4107
  };
4050
4108
  }
4051
4109
  /**
4052
- * 清空镜像(登出 / 换账号:状态是**按人**的,留着会串号),并**作废在飞的请求**。
4110
+ * 清空镜像(换账号:状态是**按人**的——分配是按人下发的、令牌是按人换的,留着会串号),
4111
+ * 并**作废在飞的请求**。
4053
4112
  *
4054
4113
  * 只清镜像是不够的:清空那一刻正有一次拉取在飞时,那次拉取是**上一个人**发起的。所以世代
4055
4114
  * +1:那之后的调用者一律不复用旧世代的那条,自己重新发一次 RPC。用世代号而**不是**把
@@ -4248,14 +4307,14 @@ function installFeatureCenter(ctx, managedMcp, managedSkills, managedWorkbench,
4248
4307
  },
4249
4308
  // PMS 个人待办面:工作台域(hiwork-workbench)按这个成员判断「有没有这个能力」,老 core 上
4250
4309
  // 它是 undefined,右栏 tab 降级成「请升级 HiWork 客户端」(spec §6 的降级矩阵第一行)。
4251
- // 七项与 spec §4.3 逐字对应;核心**只发端点调用**——凭据与 token 全在 Host(§3 D6)。
4252
- // `setStatus` 在面里折成 void(§4.3 冻结的形状),仓库返回值留给诊断与测试。
4253
- // `myTasks` / `completeTask` 是 §3 D7 追加的两项,**在面里也是可选成员**(旧 core 只有前七项,
4310
+ // 六项与 spec §4.4 逐字对应;核心**只发端点调用**——零输入登录(网关断言 → PMS 换令牌)
4311
+ // 整段在 Host 半边,客户端连断言都看不到(§3 D1 / D6)。
4312
+ // `setStatus` 在面里折成 void(§4.4 冻结的形状),仓库返回值留给诊断与测试。
4313
+ // `myTasks` / `completeTask` 是 §3 D7 追加的两项,**在面里也是可选成员**(旧 core 只有前六项,
4254
4314
  // 消费方按 `face.pmsTodo.myTasks !== undefined` 判断,见 src/client/pms-todo.ts 的版本闸口)。
4315
+ // 没有 `login` / `logout`(spec §3 D3 随账号密码通道一起删除):本面不许再长出任何凭据入口。
4255
4316
  pmsTodo: {
4256
4317
  status: () => pmsTodo.status(),
4257
- login: async (input) => await pmsTodo.login(input),
4258
- logout: async () => await pmsTodo.logout(),
4259
4318
  today: async (signal) => await pmsTodo.today(signal),
4260
4319
  statistics: async (signal) => await pmsTodo.statistics(signal),
4261
4320
  setStatus: async (input) => {