hiwork-core 0.0.35 → 0.0.38

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/index.js CHANGED
@@ -8267,7 +8267,7 @@ defineMethod("transform", [
8267
8267
  ], ({ inner }, isInner) => inner.toString(isInner));
8268
8268
 
8269
8269
  // src/version.ts
8270
- var PKG_VERSION = false ? "dev" : "0.0.35";
8270
+ var PKG_VERSION = false ? "dev" : "0.0.38";
8271
8271
 
8272
8272
  // src/browser-login.ts
8273
8273
  import { createHash, randomBytes, randomUUID } from "node:crypto";
@@ -8549,21 +8549,28 @@ async function startBrowserLogin(opts) {
8549
8549
  }
8550
8550
  return { authorizeUrl, state };
8551
8551
  }
8552
- async function failBrowserLogin(state, loginError) {
8553
- await state.patch({
8554
- set: { lastError: loginError },
8555
- unset: ["browserLoginRequest", "browserLogin"]
8556
- }).catch(() => {
8557
- });
8552
+ async function failBrowserLogin(state, loginError, log) {
8553
+ try {
8554
+ await state.patch({
8555
+ set: { lastError: loginError },
8556
+ unset: ["browserLoginRequest", "browserLogin"]
8557
+ });
8558
+ } catch (error) {
8559
+ log(`hiwork-core: \u6D4F\u89C8\u5668\u6388\u6743\u5931\u8D25\u6001\u5199\u56DE\u88AB\u62D2\uFF0C\u754C\u9762\u53EF\u80FD\u505C\u5728\u300C\u7B49\u5F85\u5B8C\u6210\u6388\u6743\u300D\uFF08${error instanceof Error ? error.message : typeof error}\uFF09`);
8560
+ }
8558
8561
  return loginError;
8559
8562
  }
8560
8563
  async function reconcileStaleBrowserLogin(state, value) {
8561
- if (value.browserLogin === void 0) return;
8562
- await state.patch({
8563
- set: { lastError: { code: "AUTH_FAILED", message: "\u4E0A\u6B21\u6D4F\u89C8\u5668\u6388\u6743\u672A\u5B8C\u6210\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55" } },
8564
- unset: ["browserLoginRequest", "browserLogin"]
8565
- }).catch(() => {
8566
- });
8564
+ if (value.browserLogin === void 0) return true;
8565
+ try {
8566
+ await state.patch({
8567
+ set: { lastError: { code: "AUTH_FAILED", message: "\u4E0A\u6B21\u6D4F\u89C8\u5668\u6388\u6743\u672A\u5B8C\u6210\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55" } },
8568
+ unset: ["browserLoginRequest", "browserLogin"]
8569
+ });
8570
+ return true;
8571
+ } catch {
8572
+ return false;
8573
+ }
8567
8574
  }
8568
8575
  async function completeBrowserLogin(input, opts) {
8569
8576
  const now = opts.now ?? Date.now;
@@ -8581,18 +8588,18 @@ async function completeBrowserLogin(input, opts) {
8581
8588
  try {
8582
8589
  if (now() - pending.startedAt > BROWSER_LOGIN_TTL_MS) {
8583
8590
  log("hiwork-core: \u6D4F\u89C8\u5668\u6388\u6743\u56DE\u8C03\u5DF2\u8D85\u65F6\uFF08\u8D85\u8FC7 10 \u5206\u949F\uFF09\uFF0C\u5DF2\u62D2\u7EDD");
8584
- return await failBrowserLogin(opts.state, { code: "AUTH_FAILED", message: "\u6388\u6743\u5DF2\u8D85\u65F6\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55" });
8591
+ return await failBrowserLogin(opts.state, { code: "AUTH_FAILED", message: "\u6388\u6743\u5DF2\u8D85\u65F6\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55" }, log);
8585
8592
  }
8586
8593
  if (typeof input.error === "string" && input.error !== "") {
8587
8594
  log(`hiwork-core: \u6D4F\u89C8\u5668\u6388\u6743\u88AB\u62D2\u7EDD\uFF08${input.error.slice(0, 64)}\uFF09`);
8588
- return await failBrowserLogin(opts.state, { code: "AUTH_FAILED", message: "\u6388\u6743\u88AB\u53D6\u6D88\u6216\u5931\u8D25\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55" });
8595
+ return await failBrowserLogin(opts.state, { code: "AUTH_FAILED", message: "\u6388\u6743\u88AB\u53D6\u6D88\u6216\u5931\u8D25\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55" }, log);
8589
8596
  }
8590
8597
  if (typeof input.code !== "string" || input.code === "") {
8591
8598
  log("hiwork-core: \u6D4F\u89C8\u5668\u6388\u6743\u56DE\u8C03\u7F3A\u5C11 code\uFF0C\u5DF2\u4E22\u5F03");
8592
- return await failBrowserLogin(opts.state, { code: "AUTH_FAILED", message: "\u6388\u6743\u56DE\u8C03\u4E0D\u5B8C\u6574\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55" });
8599
+ return await failBrowserLogin(opts.state, { code: "AUTH_FAILED", message: "\u6388\u6743\u56DE\u8C03\u4E0D\u5B8C\u6574\uFF0C\u8BF7\u91CD\u65B0\u767B\u5F55" }, log);
8593
8600
  }
8594
8601
  const baseURL = opts.value.baseURL;
8595
- if (baseURL === void 0 || baseURL === "") return await failBrowserLogin(opts.state, NO_BASE_URL_ERROR);
8602
+ if (baseURL === void 0 || baseURL === "") return await failBrowserLogin(opts.state, NO_BASE_URL_ERROR, log);
8596
8603
  const { sessionCookie, user } = await opts.gateway.exchangeCode({
8597
8604
  code: input.code,
8598
8605
  codeVerifier: pending.codeVerifier,
@@ -8617,7 +8624,7 @@ async function completeBrowserLogin(input, opts) {
8617
8624
  return null;
8618
8625
  } catch (error) {
8619
8626
  const loginError = toLoginError(error, "\u65E0\u6CD5\u8FDE\u63A5\u7F51\u5173\uFF0C\u8BF7\u68C0\u67E5 baseURL \u6216\u7F51\u7EDC");
8620
- return await failBrowserLogin(opts.state, loginError);
8627
+ return await failBrowserLogin(opts.state, loginError, log);
8621
8628
  } finally {
8622
8629
  pendingAuth = void 0;
8623
8630
  }
@@ -12483,7 +12490,7 @@ var Service = class Service2 {
12483
12490
  }
12484
12491
  };
12485
12492
 
12486
- // node_modules/.pnpm/@deepseek-ai+dsh-scope@0.1.7-rc.2_@deepseek-ai+cordis@4.0.4_@deepseek-ai+dsh-invariants_0271d3a82adfe807020938592f267574/node_modules/@deepseek-ai/dsh-scope/lib/index.js
12493
+ // node_modules/.pnpm/@deepseek-ai+dsh-scope@0.2.0-rc.1_@deepseek-ai+cordis@4.0.4_@deepseek-ai+dsh-invariants_8ef32aa4891a716d53102df556bb759f/node_modules/@deepseek-ai/dsh-scope/lib/index.js
12487
12494
  var NamedEntries = class {
12488
12495
  duplicateError;
12489
12496
  data = /* @__PURE__ */ new Map();
@@ -12699,10 +12706,10 @@ function scopeTarget(base, key) {
12699
12706
  return carrier;
12700
12707
  }
12701
12708
 
12702
- // node_modules/.pnpm/@deepseek-ai+dsh-llm@0.1.7-rc.2_@deepseek-ai+cordis@4.0.4/node_modules/@deepseek-ai/dsh-llm/lib/index.js
12709
+ // node_modules/.pnpm/@deepseek-ai+dsh-llm@0.2.0-rc.1_@deepseek-ai+cordis@4.0.4/node_modules/@deepseek-ai/dsh-llm/lib/index.js
12703
12710
  import { createRequire } from "node:module";
12704
12711
 
12705
- // node_modules/.pnpm/@deepseek-ai+dsh-typert-protocol@0.1.7-rc.2_@deepseek-ai+cordis@4.0.4/node_modules/@deepseek-ai/dsh-typert-protocol/lib/index.js
12712
+ // node_modules/.pnpm/@deepseek-ai+dsh-typert-protocol@0.2.0-rc.1_@deepseek-ai+cordis@4.0.4/node_modules/@deepseek-ai/dsh-typert-protocol/lib/index.js
12706
12713
  var RemoteError = class extends Error {
12707
12714
  code;
12708
12715
  details;
@@ -12827,7 +12834,7 @@ function validateName(subject, value) {
12827
12834
  if (!isTypertRemoteSegment(value)) throw new TypeError(`typert-protocol: ${subject} must contain only RPC endpoint segment characters`);
12828
12835
  }
12829
12836
 
12830
- // node_modules/.pnpm/@deepseek-ai+dsh-util-values@0.1.7-rc.2_@deepseek-ai+cordis@4.0.4/node_modules/@deepseek-ai/dsh-util-values/lib/index.js
12837
+ // node_modules/.pnpm/@deepseek-ai+dsh-util-values@0.2.0-rc.1_@deepseek-ai+cordis@4.0.4/node_modules/@deepseek-ai/dsh-util-values/lib/index.js
12831
12838
  function assertNever(value, context) {
12832
12839
  const rendered = JSON.stringify(value) ?? String(value);
12833
12840
  throw new Error(`unreachable variant${context ? ` in ${context}` : ""}: ${rendered}`);
@@ -12836,7 +12843,7 @@ function hasIntrinsicConstructor(prototype, name2) {
12836
12843
  const constructor = Object.getOwnPropertyDescriptor(prototype, "constructor")?.value;
12837
12844
  if (typeof constructor !== "function") return false;
12838
12845
  try {
12839
- return constructor.name === name2 && constructor.prototype === prototype && Function.prototype.toString.call(constructor) === `function ${name2}() { [native code] }`;
12846
+ return constructor.name === name2 && constructor.prototype === prototype && Function.prototype.toString.call(constructor) === Function.prototype.toString.call(name2 === "Array" ? Array : Object);
12840
12847
  } catch {
12841
12848
  return false;
12842
12849
  }
@@ -13008,7 +13015,7 @@ function deepFreeze(value) {
13008
13015
  return value;
13009
13016
  }
13010
13017
 
13011
- // node_modules/.pnpm/@deepseek-ai+dsh-util-crypto@0.1.7-rc.2_@deepseek-ai+cordis@4.0.4/node_modules/@deepseek-ai/dsh-util-crypto/lib/index.js
13018
+ // node_modules/.pnpm/@deepseek-ai+dsh-util-crypto@0.2.0-rc.1_@deepseek-ai+cordis@4.0.4/node_modules/@deepseek-ai/dsh-util-crypto/lib/index.js
13012
13019
  function randomUUID2() {
13013
13020
  const bytes = globalThis.crypto.getRandomValues(new Uint8Array(16));
13014
13021
  const hex = Array.from(bytes, (byte, index) => {
@@ -13017,15 +13024,15 @@ function randomUUID2() {
13017
13024
  return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
13018
13025
  }
13019
13026
 
13020
- // node_modules/.pnpm/@deepseek-ai+dsh-brand@0.1.7-rc.2_@deepseek-ai+cordis@4.0.4/node_modules/@deepseek-ai/dsh-brand/lib/index.js
13027
+ // node_modules/.pnpm/@deepseek-ai+dsh-brand@0.2.0-rc.1_@deepseek-ai+cordis@4.0.4/node_modules/@deepseek-ai/dsh-brand/lib/index.js
13021
13028
  function brandString(value) {
13022
13029
  return value;
13023
13030
  }
13024
13031
 
13025
- // node_modules/.pnpm/@deepseek-ai+dsh-timeout@0.1.7-rc.2_@deepseek-ai+cordis@4.0.4/node_modules/@deepseek-ai/dsh-timeout/lib/index.js
13032
+ // node_modules/.pnpm/@deepseek-ai+dsh-timeout@0.2.0-rc.1_@deepseek-ai+cordis@4.0.4/node_modules/@deepseek-ai/dsh-timeout/lib/index.js
13026
13033
  var MAX_TIMER_DELAY_MS = 2147483647;
13027
13034
 
13028
- // node_modules/.pnpm/@deepseek-ai+dsh-llm@0.1.7-rc.2_@deepseek-ai+cordis@4.0.4/node_modules/@deepseek-ai/dsh-llm/lib/index.js
13035
+ // node_modules/.pnpm/@deepseek-ai+dsh-llm@0.2.0-rc.1_@deepseek-ai+cordis@4.0.4/node_modules/@deepseek-ai/dsh-llm/lib/index.js
13029
13036
  function freezeMessage(message) {
13030
13037
  return deepFreeze(structuredClone(message));
13031
13038
  }
@@ -14068,7 +14075,7 @@ function adapterFailureChunk(error, signal) {
14068
14075
  };
14069
14076
  }
14070
14077
 
14071
- // node_modules/.pnpm/@deepseek-ai+dsh-sandbox@0.1.7-rc.2_@deepseek-ai+cordis@4.0.4_@deepseek-ai+dsh-llm@0.1._a8c9906be8c926809212c5fbb3bc7c61/node_modules/@deepseek-ai/dsh-sandbox/lib/index.js
14078
+ // node_modules/.pnpm/@deepseek-ai+dsh-sandbox@0.2.0-rc.1_@deepseek-ai+cordis@4.0.4_@deepseek-ai+dsh-llm@0.2._910788faa6d5e8808178f15deb98d164/node_modules/@deepseek-ai/dsh-sandbox/lib/index.js
14072
14079
  var WIDER_MODES = {
14073
14080
  "read-only": ["workspace-write", "danger-full-access"],
14074
14081
  "workspace-write": ["danger-full-access"]
@@ -14110,7 +14117,7 @@ async function approveEscalation(request, approval) {
14110
14117
  }
14111
14118
  }
14112
14119
 
14113
- // node_modules/.pnpm/@deepseek-ai+dsh-tools@0.1.7-rc.2_d2e08270f2205e73d65e98cfcd910cae/node_modules/@deepseek-ai/dsh-tools/lib/index.js
14120
+ // node_modules/.pnpm/@deepseek-ai+dsh-tools@0.2.0-rc.1_44958e8f826516598aa7d335d84aa068/node_modules/@deepseek-ai/dsh-tools/lib/index.js
14114
14121
  var JsonSchemaError = class extends HarnessError {
14115
14122
  /** Individual schema violations in walk order. */
14116
14123
  violations;
@@ -19125,6 +19132,42 @@ function provideIdentity(ctx, deps) {
19125
19132
  };
19126
19133
  }
19127
19134
 
19135
+ // src/identity-context.ts
19136
+ var IDENTITY_CONTEXT_NAME = "hiwork:identity";
19137
+ var IDENTITY_CONTEXT_ORDER = 105;
19138
+ var CAVEAT = "\u8BE5\u8EAB\u4EFD\u7528\u4E8E\u4E2A\u6027\u5316\u4E0E\u6309\u4EBA\u8868\u8FF0\uFF1B\u6D89\u53CA\u6570\u636E\u6743\u9650\u7684\u64CD\u4F5C\u5FC5\u987B\u8D70\u53D7\u7BA1\u5DE5\u5177/\u8FDE\u63A5\u5668\u5B8C\u6210\uFF0C\u4E0D\u5F97\u628A\u6B64\u6587\u672C\u5F53\u4F5C\u51ED\u8BC1\u3002";
19139
+ function textOrUndefined6(value) {
19140
+ if (typeof value !== "string") return void 0;
19141
+ const text = value.trim();
19142
+ return text === "" ? void 0 : text;
19143
+ }
19144
+ function renderIdentityContextText(state) {
19145
+ const username = textOrUndefined6(state?.username);
19146
+ if (username === void 0) return "";
19147
+ const displayName = textOrUndefined6(state?.displayName);
19148
+ const who = displayName === void 0 ? `\u5DE5\u53F7 ${username}` : `${displayName}\uFF08\u5DE5\u53F7 ${username}\uFF09`;
19149
+ return `HiWork \u767B\u5F55\u8EAB\u4EFD\uFF1A${who}\u3002${CAVEAT}`;
19150
+ }
19151
+ function registerIdentityContext(systemPrompt, deps) {
19152
+ const dispose = systemPrompt.context({
19153
+ name: IDENTITY_CONTEXT_NAME,
19154
+ order: IDENTITY_CONTEXT_ORDER,
19155
+ text: () => {
19156
+ try {
19157
+ if (!deps.enabled()) return "";
19158
+ return renderIdentityContextText(deps.current());
19159
+ } catch (error) {
19160
+ deps.log?.(
19161
+ `hiwork-core: \u767B\u5F55\u8EAB\u4EFD\u4E0A\u4E0B\u6587\u8BFB\u53D6\u5931\u8D25\uFF08${error instanceof Error ? error.name : typeof error}\uFF09`
19162
+ );
19163
+ return "";
19164
+ }
19165
+ }
19166
+ });
19167
+ return typeof dispose === "function" ? dispose : () => {
19168
+ };
19169
+ }
19170
+
19128
19171
  // src/knowledge-config.ts
19129
19172
  var HIWORK_KNOWLEDGE_SERVICE = "hiworkKnowledge";
19130
19173
  var ME_KNOWLEDGE_CONFIG_PATH = "/api/me/knowledge-config";
@@ -19151,22 +19194,22 @@ function messageFor(reason) {
19151
19194
  function failure12(reason, message) {
19152
19195
  return { ok: false, reason, message: message ?? messageFor(reason) };
19153
19196
  }
19154
- function textOrUndefined6(value) {
19197
+ function textOrUndefined7(value) {
19155
19198
  if (typeof value !== "string") return void 0;
19156
19199
  const text = value.trim();
19157
19200
  return text === "" ? void 0 : text;
19158
19201
  }
19159
19202
  function projectKnowledgeConfig(body) {
19160
- const baseUrl = textOrUndefined6(body["base_url"] ?? body["baseUrl"]);
19161
- const apiKey = textOrUndefined6(body["api_key"] ?? body["apiKey"]);
19203
+ const baseUrl = textOrUndefined7(body["base_url"] ?? body["baseUrl"]);
19204
+ const apiKey = textOrUndefined7(body["api_key"] ?? body["apiKey"]);
19162
19205
  if (baseUrl === void 0 || apiKey === void 0) return void 0;
19163
19206
  return {
19164
19207
  ok: true,
19165
19208
  baseUrl,
19166
19209
  apiKey,
19167
- agentId: textOrUndefined6(body["agent_id"] ?? body["agentId"]) ?? "",
19168
- chatModelId: textOrUndefined6(body["chat_model_id"] ?? body["chatModelId"]) ?? "",
19169
- tenantId: textOrUndefined6(body["tenant_id"] ?? body["tenantId"]) ?? "",
19210
+ agentId: textOrUndefined7(body["agent_id"] ?? body["agentId"]) ?? "",
19211
+ chatModelId: textOrUndefined7(body["chat_model_id"] ?? body["chatModelId"]) ?? "",
19212
+ tenantId: textOrUndefined7(body["tenant_id"] ?? body["tenantId"]) ?? "",
19170
19213
  knowledgeBases: projectKnowledgeBases(body["knowledge_bases"] ?? body["knowledgeBases"])
19171
19214
  };
19172
19215
  }
@@ -19177,10 +19220,10 @@ function projectKnowledgeBases(value) {
19177
19220
  for (const item of value) {
19178
19221
  if (item === null || typeof item !== "object") continue;
19179
19222
  const record = item;
19180
- const id = textOrUndefined6(record["id"]);
19223
+ const id = textOrUndefined7(record["id"]);
19181
19224
  if (id === void 0 || seen.has(id)) continue;
19182
19225
  seen.add(id);
19183
- bases.push({ id, name: textOrUndefined6(record["name"]) ?? "" });
19226
+ bases.push({ id, name: textOrUndefined7(record["name"]) ?? "" });
19184
19227
  }
19185
19228
  return bases.length === 0 ? EMPTY_KNOWLEDGE_BASES : bases;
19186
19229
  }
@@ -19236,8 +19279,8 @@ var KnowledgeConfigProvider = class {
19236
19279
  const raw = await gateway.getMyKnowledgeToken(sessionCookie);
19237
19280
  const envelope = raw;
19238
19281
  const body = envelope?.["data"] && typeof envelope["data"] === "object" ? envelope["data"] : envelope;
19239
- const token = textOrUndefined6(body?.["token"] ?? body?.["knowledge_token"]);
19240
- const audience = textOrUndefined6(body?.["audience"] ?? body?.["aud"]);
19282
+ const token = textOrUndefined7(body?.["token"] ?? body?.["knowledge_token"]);
19283
+ const audience = textOrUndefined7(body?.["audience"] ?? body?.["aud"]);
19241
19284
  const ids = body?.["knowledge_base_ids"] ?? body?.["knowledgeBaseIds"];
19242
19285
  if (!token || audience !== "hiwork-knowledge" || !Array.isArray(ids) || !ids.every((id) => typeof id === "string")) {
19243
19286
  this.deps.log?.("hiwork-core: \u7F51\u5173\u8FD4\u56DE\u7684 knowledge-token \u5F62\u72B6\u65E0\u6548");
@@ -19248,8 +19291,8 @@ var KnowledgeConfigProvider = class {
19248
19291
  const knowledgeBases = Array.isArray(rawBases) ? rawBases.flatMap((item) => {
19249
19292
  if (item === null || typeof item !== "object") return [];
19250
19293
  const obj = item;
19251
- const id = textOrUndefined6(obj["id"]);
19252
- return id ? [{ id, name: textOrUndefined6(obj["name"]) ?? "" }] : [];
19294
+ const id = textOrUndefined7(obj["id"]);
19295
+ return id ? [{ id, name: textOrUndefined7(obj["name"]) ?? "" }] : [];
19253
19296
  }).filter((item) => knowledgeBaseIds.includes(item.id)) : [];
19254
19297
  const view = { ok: true, token, audience, knowledgeBaseIds, knowledgeBases };
19255
19298
  this.tokenCached = { sessionCookie, view, at: this.now() };
@@ -19367,7 +19410,7 @@ function messageFor2(reason) {
19367
19410
  function failure13(reason, message) {
19368
19411
  return { ok: false, reason, message: message ?? messageFor2(reason) };
19369
19412
  }
19370
- function textOrUndefined7(value) {
19413
+ function textOrUndefined8(value) {
19371
19414
  if (typeof value !== "string") return void 0;
19372
19415
  const text = value.trim();
19373
19416
  return text === "" ? void 0 : text;
@@ -19376,15 +19419,15 @@ function teamIdsOf(value) {
19376
19419
  if (!Array.isArray(value)) return [];
19377
19420
  const ids = [];
19378
19421
  for (const item of value) {
19379
- const text = textOrUndefined7(item);
19422
+ const text = textOrUndefined8(item);
19380
19423
  if (text !== void 0) ids.push(text);
19381
19424
  }
19382
19425
  return ids;
19383
19426
  }
19384
19427
  function projectMemoryConfig(body) {
19385
- const panelUrl = textOrUndefined7(body["panel_url"] ?? body["panelUrl"]);
19386
- const serviceId = textOrUndefined7(body["service_id"] ?? body["serviceId"]);
19387
- const apiKey = textOrUndefined7(body["api_key"] ?? body["apiKey"] ?? body["userKey"]);
19428
+ const panelUrl = textOrUndefined8(body["panel_url"] ?? body["panelUrl"]);
19429
+ const serviceId = textOrUndefined8(body["service_id"] ?? body["serviceId"]);
19430
+ const apiKey = textOrUndefined8(body["api_key"] ?? body["apiKey"] ?? body["userKey"]);
19388
19431
  if (panelUrl === void 0 || serviceId === void 0 || apiKey === void 0) return void 0;
19389
19432
  return {
19390
19433
  ok: true,
@@ -19651,7 +19694,7 @@ function provideOfficeRelay(ctx, deps) {
19651
19694
  };
19652
19695
  }
19653
19696
 
19654
- // node_modules/.pnpm/@deepseek-ai+dsh-web@0.1.7-rc.2_@deepseek-ai+cordis@4.0.4_@deepseek-ai+dsh-llm@0.1.7-rc.2_@deepseek-ai+cordis@4.0.4_/node_modules/@deepseek-ai/dsh-web/lib/index.js
19697
+ // node_modules/.pnpm/@deepseek-ai+dsh-web@0.2.0-rc.1_@deepseek-ai+cordis@4.0.4_@deepseek-ai+dsh-llm@0.2.0-rc.1_@deepseek-ai+cordis@4.0.4_/node_modules/@deepseek-ai/dsh-web/lib/index.js
19655
19698
  var WebError = class extends HarnessError {
19656
19699
  };
19657
19700
  var WebRuntime = class extends Service {
@@ -19829,7 +19872,7 @@ function httpOutcomeToError(status, code) {
19829
19872
  if (status === 502 || code === "SEARCH_UPSTREAM_ERROR") return new WebError("\u641C\u7D22\u670D\u52A1\u6682\u65F6\u4E0D\u53EF\u7528\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5", HIWORK_SEARCH_UPSTREAM);
19830
19873
  return new WebError("\u8054\u7F51\u641C\u7D22\u6682\u65F6\u4E0D\u53EF\u7528\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5", "WEB_PROVIDER_ERROR");
19831
19874
  }
19832
- function textOrUndefined8(value) {
19875
+ function textOrUndefined9(value) {
19833
19876
  if (typeof value !== "string") return void 0;
19834
19877
  const text = value.trim();
19835
19878
  return text === "" ? void 0 : text;
@@ -19841,11 +19884,11 @@ function projectWebSearch(body) {
19841
19884
  for (const item of raw) {
19842
19885
  if (item === null || typeof item !== "object") continue;
19843
19886
  const record = item;
19844
- const url = textOrUndefined8(record["url"]);
19887
+ const url = textOrUndefined9(record["url"]);
19845
19888
  if (url === void 0) continue;
19846
- const title = textOrUndefined8(record["title"]);
19847
- const snippet = textOrUndefined8(record["snippet"]) ?? textOrUndefined8(record["content"]);
19848
- const publishedAt = textOrUndefined8(record["published_at"]);
19889
+ const title = textOrUndefined9(record["title"]);
19890
+ const snippet = textOrUndefined9(record["snippet"]) ?? textOrUndefined9(record["content"]);
19891
+ const publishedAt = textOrUndefined9(record["published_at"]);
19849
19892
  sources.push({
19850
19893
  url,
19851
19894
  ...title !== void 0 ? { title } : {},
@@ -19909,7 +19952,7 @@ function registerManagedSearchProvider(web, deps) {
19909
19952
 
19910
19953
  // src/index.ts
19911
19954
  var name = "hiwork-core";
19912
- var inject = ["settings", "credentials", "workspaceRegistry", "connection", "web", "agents"];
19955
+ var inject = ["settings", "credentials", "workspaceRegistry", "connection", "web", "agents", "systemPrompt"];
19913
19956
  var NS = "ai-router";
19914
19957
  var PI_AI_NS = "llm-pi-ai";
19915
19958
  var MenuConfig = Schema.object({
@@ -19921,6 +19964,8 @@ var MenuConfig = Schema.object({
19921
19964
  var lastErrorSchema = Schema.object({ code: Schema.string().required(), message: Schema.string().required() }).default(void 0);
19922
19965
  var Config = Schema.object({
19923
19966
  baseURL: Schema.string(),
19967
+ // 非 volatile:与 baseURL 同类的组合层固定配置(不进用户表单),出问题经 bundle patch 关闭。
19968
+ identityContext: Schema.boolean().default(true),
19924
19969
  keyId: Schema.string().volatile(),
19925
19970
  username: Schema.string().volatile(),
19926
19971
  displayName: Schema.string().volatile(),
@@ -19959,19 +20004,45 @@ function pathOps(patch) {
19959
20004
  for (const key of patch.unset ?? []) ops.push({ op: "unset", path: [key] });
19960
20005
  return ops;
19961
20006
  }
19962
- async function writeNamespace(settings, ns, ops) {
19963
- for (let attempt = 0; attempt < 2; attempt++) {
20007
+ var HMR_NESTED_FRAGMENT = "HMR transactions cannot be nested";
20008
+ var ENTRY_UNAVAILABLE_FRAGMENTS = ["No configurable plugin entry", "is no longer configurable"];
20009
+ var WRITE_DEADLINE_MS = 15e3;
20010
+ var WRITE_BACKOFF_MIN_MS = 50;
20011
+ var WRITE_BACKOFF_MAX_MS = 1e3;
20012
+ function isHmrNestedWriteError(error) {
20013
+ return error instanceof Error && error.message.includes(HMR_NESTED_FRAGMENT);
20014
+ }
20015
+ function isRetriableWriteError(error) {
20016
+ if (!(error instanceof Error)) return false;
20017
+ return error.name === "SettingsConflictError" || isHmrNestedWriteError(error) || ENTRY_UNAVAILABLE_FRAGMENTS.some((fragment) => error.message.includes(fragment));
20018
+ }
20019
+ function delay(ms) {
20020
+ return new Promise((resolve3) => {
20021
+ setTimeout(resolve3, ms);
20022
+ });
20023
+ }
20024
+ async function writeNamespace(settings, ns, ops, opts = {}) {
20025
+ const deadline = Date.now() + (opts.deadlineMs ?? WRITE_DEADLINE_MS);
20026
+ const maxBackoff = opts.maxBackoffMs ?? WRITE_BACKOFF_MAX_MS;
20027
+ let backoff = opts.minBackoffMs ?? WRITE_BACKOFF_MIN_MS;
20028
+ for (; ; ) {
19964
20029
  const descriptor = settings.describe().find((d) => d.ns === ns);
19965
- if (descriptor === void 0) throw new Error(`settings namespace "${ns}" is not registered`);
20030
+ if (descriptor === void 0) {
20031
+ if (Date.now() >= deadline) throw new Error(`settings namespace "${ns}" is not registered`);
20032
+ await delay(backoff);
20033
+ backoff = Math.min(backoff * 2, maxBackoff);
20034
+ continue;
20035
+ }
19966
20036
  try {
19967
20037
  await settings.mutate(ns, ops, descriptor.revision);
19968
20038
  return;
19969
20039
  } catch (error) {
19970
- if (error instanceof Error && error.name === "SettingsConflictError") continue;
19971
- throw error;
20040
+ if (!isRetriableWriteError(error)) throw error;
20041
+ if (Date.now() >= deadline) throw error;
20042
+ await delay(backoff);
20043
+ backoff = Math.min(backoff * 2, maxBackoff);
19972
20044
  }
19973
20045
  }
19974
- throw new Error(`settings namespace "${ns}" write conflicted repeatedly`);
19975
20046
  }
19976
20047
  function readDefaultSelection(settings) {
19977
20048
  const value = settings.describe().find((d) => d.ns === DEFAULT_MODEL_NS)?.value;
@@ -20188,6 +20259,8 @@ async function importLegacyMenuSection(opts) {
20188
20259
  log(`hiwork-core: \u65E7\u7248\u83DC\u5355\u504F\u597D\u8FC1\u79FB\u5931\u8D25\uFF08${error instanceof Error ? error.name : typeof error}\uFF09`);
20189
20260
  }
20190
20261
  }
20262
+ var STALE_BROWSER_LOGIN_RECONCILE_DELAYS_MS = [0, 500, 1500, 4e3, 8e3];
20263
+ var LOGIN_REQUEST_POLL_MS = 200;
20191
20264
  function apply(ctx, config) {
20192
20265
  const current = () => plainValue(config);
20193
20266
  const settings = ctx.get("settings");
@@ -20266,9 +20339,7 @@ function apply(ctx, config) {
20266
20339
  }).catch(() => {
20267
20340
  });
20268
20341
  };
20269
- ctx.on("settings/document-updated", (ns) => {
20270
- if (ns !== NS) return;
20271
- requestClientPolicy();
20342
+ const dispatchSectionChange = () => {
20272
20343
  const value = current();
20273
20344
  const requested = value.pendingLogin ?? value.browserLoginRequest ?? value.refreshRequest ?? value.logoutRequest;
20274
20345
  if (requested === void 0) return;
@@ -20286,18 +20357,36 @@ function apply(ctx, config) {
20286
20357
  });
20287
20358
  } catch (error) {
20288
20359
  ctx.logger.error("hiwork-core: ai-router section change failed", error);
20360
+ if (isHmrNestedWriteError(error)) {
20361
+ ctx.logger.warn("hiwork-core: \u8F6E\u8BE2\u4E0A\u4E0B\u6587\u5DF2\u88AB HMR \u4E8B\u52A1\u6C61\u67D3\uFF0C\u672C\u5B9E\u4F8B\u540E\u7EED\u56DE\u5199\u5C06\u5168\u90E8\u88AB\u62D2\uFF08\u9700\u91CD\u6302\u63D2\u4EF6\u6216\u91CD\u542F\u5E94\u7528\uFF09");
20362
+ }
20289
20363
  await ports.credentials.unset(PENDING_PASSWORD_REF).catch(() => {
20290
20364
  });
20291
- await ports.state.patch({
20292
- set: { lastError: { code: "GATEWAY_UNREACHABLE", message: "\u7F51\u5173\u63D2\u4EF6\u5904\u7406\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u914D\u7F6E\u4E0E\u7F51\u7EDC" } },
20293
- unset: ["pendingLogin", "browserLoginRequest", "browserLogin", "refreshRequest", "logoutRequest"]
20294
- }).catch(() => {
20295
- });
20365
+ try {
20366
+ await ports.state.patch({
20367
+ set: { lastError: { code: "GATEWAY_UNREACHABLE", message: "\u7F51\u5173\u63D2\u4EF6\u5904\u7406\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u914D\u7F6E\u4E0E\u7F51\u7EDC" } },
20368
+ unset: ["pendingLogin", "browserLoginRequest", "browserLogin", "refreshRequest", "logoutRequest"]
20369
+ });
20370
+ } catch (patchError) {
20371
+ ctx.logger.error("hiwork-core: ai-router \u8BF7\u6C42\u5B57\u6BB5\u6E05\u7406\u5931\u8D25\uFF0C\u754C\u9762\u53EF\u80FD\u505C\u5728\u7B49\u5F85\u4E2D", patchError);
20372
+ }
20296
20373
  }
20297
20374
  })().finally(() => {
20298
20375
  inFlight = void 0;
20299
20376
  });
20300
- });
20377
+ };
20378
+ ctx.effect(() => {
20379
+ const consume = () => {
20380
+ requestClientPolicy();
20381
+ dispatchSectionChange();
20382
+ };
20383
+ consume();
20384
+ const timer = setInterval(consume, LOGIN_REQUEST_POLL_MS);
20385
+ timer.unref?.();
20386
+ return () => {
20387
+ clearInterval(timer);
20388
+ };
20389
+ }, "hiwork-core: login request poll");
20301
20390
  void ctx.root.loader.await().then(() => importLegacyMenuSection({
20302
20391
  ctx,
20303
20392
  settings,
@@ -20306,7 +20395,15 @@ function apply(ctx, config) {
20306
20395
  ctx.logger.warn(`hiwork-core: \u65E7\u7248\u83DC\u5355\u504F\u597D\u8FC1\u79FB\u672A\u6267\u884C\uFF08${error instanceof Error ? error.name : typeof error}\uFF09`);
20307
20396
  });
20308
20397
  requestClientPolicy();
20309
- void reconcileStaleBrowserLogin(ports.state, current());
20398
+ void (async () => {
20399
+ for (const delay2 of STALE_BROWSER_LOGIN_RECONCILE_DELAYS_MS) {
20400
+ if (delay2 > 0) await new Promise((resolve3) => {
20401
+ setTimeout(resolve3, delay2);
20402
+ });
20403
+ if (await reconcileStaleBrowserLogin(ports.state, current())) return;
20404
+ }
20405
+ ctx.logger.warn("hiwork-core: \u6D4F\u89C8\u5668\u6388\u6743\u7B49\u5F85\u6001\u5BF9\u8D26\u672A\u5199\u5165\uFF0C\u754C\u9762\u53EF\u80FD\u505C\u5728\u300C\u7B49\u5F85\u5B8C\u6210\u6388\u6743\u300D");
20406
+ })();
20310
20407
  const connection = ctx.get("connection");
20311
20408
  if (connection === void 0) throw new Error("connection service unavailable");
20312
20409
  ctx.effect(() => registerUsageRpc({ connection, logger: ctx.logger }, {
@@ -20540,6 +20637,13 @@ function apply(ctx, config) {
20540
20637
  ctx.logger.warn(message);
20541
20638
  }
20542
20639
  }), "hiwork-core: identity service");
20640
+ ctx.effect(() => registerIdentityContext(ctx.systemPrompt, {
20641
+ current: () => current(),
20642
+ enabled: () => current().identityContext !== false,
20643
+ log: (message) => {
20644
+ ctx.logger.warn(message);
20645
+ }
20646
+ }), "hiwork-core: identity runtime context");
20543
20647
  ctx.effect(() => provideMemoryConfig(ctx, {
20544
20648
  resolveSession: async () => (await ports.credentials.resolve(SESSION_REF))?.value,
20545
20649
  gateway: () => {
@@ -20638,8 +20742,10 @@ export {
20638
20742
  apply,
20639
20743
  createDefaultModelPort,
20640
20744
  inject,
20745
+ isHmrNestedWriteError,
20641
20746
  name,
20642
20747
  plainValue,
20643
20748
  projectLoginMode,
20644
- registerIpcMessageHandler
20749
+ registerIpcMessageHandler,
20750
+ writeNamespace
20645
20751
  };
@@ -80,11 +80,20 @@ export declare function startBrowserLogin(opts: BrowserLoginStartPorts): Promise
80
80
  * `browserLogin` 是持久化的。宿主一旦重启(应用重开、DSH 崩溃重启、开发期 HMR),
81
81
  * 两者就永久错位:所有回调都被 `completeBrowserLogin` 的「没有待完成的授权请求」丢弃,
82
82
  * 界面却仍按持久化的 `browserLogin` 停在「等待完成授权」,用户只能靠「取消」脱困。
83
+ * 更糟的是登录门挂载时会拿这个**已经死掉的**授权 URL 自动打开浏览器,用户无论怎么
84
+ * 在浏览器里完成授权都回不来——这正是「浏览器打开了但授权回不到桌面端」的成因。
83
85
  *
84
86
  * 因此启动即把这种**不可能完成**的等待态收尾成失败:写一条 lastError 并清掉等待字段,
85
87
  * 让用户回到登录入口重新发起。没有等待态时不动任何状态。
88
+ *
89
+ * ⚠️ **返回值必须被检查,调用方必须重试**:`apply()` 跑在任何 settings 写入可用之前,
90
+ * 此时写回会被 `settings namespace "<ns>" is not registered` 拒绝(实测 1.0.8 桌面端:
91
+ * apply 时刻命名空间尚未注册,约 3.7s 后才可写)。捕获后吞掉这个拒绝,等于等待态永远
92
+ * 清不掉——本函数原先正是 `.catch(() => {})` + 单次调用,缺陷即由此而来。
93
+ *
94
+ * @returns `true` = 已收尾(原本就没有等待态,或已成功清掉);`false` = 写回被拒,需重试。
86
95
  */
87
- export declare function reconcileStaleBrowserLogin(state: AiRouterStatePort, value: Pick<AiRouterNamespaceValue, 'browserLogin'>): Promise<void>;
96
+ export declare function reconcileStaleBrowserLogin(state: AiRouterStatePort, value: Pick<AiRouterNamespaceValue, 'browserLogin'>): Promise<boolean>;
88
97
  /**
89
98
  * 处理 `hiwork://auth/callback`:校验 state → 兑换一次性 code → 写会话凭据 → 复用供给尾部。
90
99
  *
@@ -20,6 +20,22 @@ export declare const DAILY_ENDPOINTS: readonly ["today", "random"];
20
20
  export type DailyEndpoint = (typeof DAILY_ENDPOINTS)[number];
21
21
  /** 失败防抖 TTL:5 分钟——观察循环逐帧触发,绝不逐帧重试网关。 */
22
22
  export declare const DAILY_FAILURE_TTL_MS: number;
23
+ /**
24
+ * 失败防抖 TTL 对「宿主本地前置失败」的替代值(毫秒)。
25
+ *
26
+ * {@link DAILY_LOCAL_FAILURE_CODES} 里的错误由 Host 在**打网之前**判定(未登录 / 网关地址未配置),
27
+ * 不产生任何网关流量;而它们在「用户完成登录」或「配置补上」之后必然变化。若也计入 5 分钟防抖,
28
+ * 就会把「登录后立刻能用」变成「最多再等 5 分钟」——**首次安装正是这个顺序**(先启动、后登录),
29
+ * 用户看到的是「首次启动没有每日一句,切几次页面 / 关掉重开才有」。
30
+ * 2 秒只为压住观察循环逐帧触发时的空转(并发已由 `pending` 合并为至多一次在途),不改变可见行为。
31
+ */
32
+ export declare const DAILY_LOCAL_RETRY_MS = 2000;
33
+ /**
34
+ * Host 在打网之前判定的失败 code(见 `src/daily-rpc.ts` 的 `handleDailyEndpoint`):
35
+ * `SESSION_EXPIRED`(未登录 / 会话失效)与 `GATEWAY_UNREACHABLE`(网关地址未配置)。
36
+ * 只豁免这两个明确「本地」的 code;网关透传的失败与未知错误一律按真实上游失败进 5 分钟防抖。
37
+ */
38
+ export declare const DAILY_LOCAL_FAILURE_CODES: readonly ["SESSION_EXPIRED", "GATEWAY_UNREACHABLE"];
23
39
  /**
24
40
  * 单条每日一句的视图形状(网关 JSON 按结构重声明后的归一结果):
25
41
  * 可选字段缺省一律归一为空串 / 空数组,视图据此隐藏对应区块。
@@ -90,20 +106,27 @@ export declare class DailyDataStore implements DailyQuoteLoader {
90
106
  private readonly rpc;
91
107
  private entry;
92
108
  private failureAt;
109
+ /** 上一次失败是否为宿主本地前置失败({@link DAILY_LOCAL_FAILURE_CODES})——决定节流用哪个 TTL。 */
110
+ private localFailure;
93
111
  private pending;
94
112
  private readonly now;
95
113
  private readonly localDay;
96
114
  private readonly failureTtlMs;
115
+ private readonly localRetryMs;
97
116
  constructor(rpc: DailyRpcPort, options?: {
98
117
  now?: (() => number) | undefined;
99
118
  localDay?: (() => number) | undefined;
100
119
  failureTtlMs?: number | undefined;
120
+ localRetryMs?: number | undefined;
101
121
  });
102
122
  /** 清空缓存与防抖状态(登出 / 换账号时调用)。 */
103
123
  clear(): void;
104
124
  /**
105
- * 当日条目:同一本地日内命中缓存直接返回(不发 RPC);失败防抖期内返回 null 不
106
- * 重复打网关;并发调用合并为同一次 RPC。返回 null 即「暂无可展示内容」。
125
+ * 当日条目:同一本地日内命中缓存直接返回(不发 RPC);节流期内返回 null 不重复打网关;
126
+ * 并发调用合并为同一次 RPC。返回 null 即「暂无可展示内容」。
127
+ *
128
+ * 节流时长分两档:宿主本地前置失败(未登录 / 网关未配置)只等 {@link DAILY_LOCAL_RETRY_MS},
129
+ * 其余失败等 {@link DAILY_FAILURE_TTL_MS}——理由见两个常量的说明(首次安装必先启动后登录)。
107
130
  */
108
131
  getToday(): Promise<DailyTodayView | null>;
109
132
  /**
@@ -111,6 +134,11 @@ export declare class DailyDataStore implements DailyQuoteLoader {
111
134
  * 失败 / 暂无随机条目返回 null(视图保持当前条目、无任何提示)。
112
135
  */
113
136
  getRandom(excludeId?: number): Promise<DailyQuoteView | null>;
114
- /** 单次 today 拉取:成功(含池空)写缓存;任何失败进入 5 分钟防抖并返回 null。 */
137
+ /**
138
+ * 单次 today 拉取:成功(含池空)写缓存;任何失败进入节流并返回 null。
139
+ *
140
+ * 失败分两档记:{@link DAILY_LOCAL_FAILURE_CODES} 是宿主在打网之前判定的(无网关流量、登录后必然变化),
141
+ * 只记短节流;其余(网关透传失败、形状非法、未知错误)记满 {@link DAILY_FAILURE_TTL_MS}。
142
+ */
115
143
  private fetchToday;
116
144
  }
@@ -15,10 +15,11 @@ export declare const HIWORK_MENU_NS = "hiwork-menu";
15
15
  /**
16
16
  * 未自定义时侧栏直显的条数上限(不含原生的「新会话」)。
17
17
  *
18
- * 达到上限之后,用户没有明确标记的入口一律进「更多」——这正是「以后再装插件也不会把侧栏顶高」
19
- * 的机制(新插件的 id 不在偏好里 = 未标记 = 超出上限就走「更多」)。
18
+ * 当前第一方入口恰为 6 个(五个业务 feature + 官方「插件」代理项 order 70)——上限取 6,
19
+ * 全量直显、「更多」行为空不渲染;第 7 个及以后的未标记入口仍走「更多」(「以后再装插件
20
+ * 也不会把侧栏顶高」的机制不变)。改这个数要同步 menu-preferences.spec 的硬编码用例。
20
21
  */
21
- export declare const DEFAULT_SIDEBAR_LIMIT = 5;
22
+ export declare const DEFAULT_SIDEBAR_LIMIT = 6;
22
23
  /** 菜单里「更多」那一行的固定 id(与 feature id 同域,但永不来自注册表)。 */
23
24
  export declare const MORE_MENU_ITEM_ID = "__hiwork_more__";
24
25
  /** 「更多」这一行的文案(hiwork-core 未注册 locale 命名空间,沿用硬编码中文)。 */
@@ -76,11 +76,12 @@ export declare const frameCss: string;
76
76
  /**
77
77
  * 隐藏宿主动作入口:
78
78
  * - 会话头部右上角「Session 日志」导出入口(产品要求不暴露会话日志导出);
79
- * - 侧栏底部官方「设置」触发钮:账号行(sidebar.footer.action)自带设置入口。
79
+ * - 侧栏底部官方「设置」触发钮:0.2 起用户徽章注册进 `settings.launcher` 单席槽位
80
+ * (priority -1 抢占官方 ui-settings-account 的账户触发行),**官方触发钮不再渲染**
81
+ * (单席槽位按优先级只出一席),这条 CSS 是 0.1.x 运行树上的兜底——徽章当时挂在
82
+ * sidebar.footer.action、官方触发钮仍在。两代部署并存无害。
80
83
  * 注意官方设置弹窗面板 portal 在 settingsArea 容器内部渲染,只能隐藏触发钮
81
- * 本身(settingsArea 整区 display:none 会连弹窗一起藏掉);触发钮留在 DOM 里
82
- * 供 openSettingsSection 程序化点击(display:none 不影响 .click() 派发,
83
- * dsh-ui 同款做法),弹窗照常打开。
84
+ * 本身(settingsArea 整区 display:none 会连弹窗一起藏掉)。
84
85
  * 均按 CSS module 语义后缀命中(hash 前缀无关)。display:none 同时移出无障碍树与
85
86
  * Tab 焦点链。后续要隐藏其他宿主入口,规则追加到这里。
86
87
  *