dsh-multi-router 0.4.1 → 0.5.1

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.
@@ -2,7 +2,7 @@ import {
2
2
  isFreeModel,
3
3
  reasoningModes,
4
4
  writePrivateJson
5
- } from "./chunk-XMXFIV5G.js";
5
+ } from "./chunk-GAQ77CH4.js";
6
6
 
7
7
  // src/telemetry.mjs
8
8
  import { readFile } from "node:fs/promises";
@@ -446,4 +446,4 @@ export {
446
446
  matchModel,
447
447
  Router
448
448
  };
449
- //# sourceMappingURL=chunk-GGRCX2NR.js.map
449
+ //# sourceMappingURL=chunk-XV7O2LRF.js.map
@@ -12,7 +12,7 @@ import {
12
12
  import {
13
13
  RouteError,
14
14
  abortable
15
- } from "./chunk-GGRCX2NR.js";
15
+ } from "./chunk-XV7O2LRF.js";
16
16
  import {
17
17
  WorkBuddyUpstreamClient,
18
18
  modelWithCurrentPromotion,
@@ -4909,7 +4909,7 @@ function cachedModels(discover, ttl) {
4909
4909
  };
4910
4910
  }
4911
4911
  async function createAccountClient(account, config, attachments) {
4912
- let chat, discover, accountInfo;
4912
+ let chat, discover, accountInfo, checkin;
4913
4913
  if (account.provider.startsWith("workbuddy")) {
4914
4914
  const client = new WorkBuddyUpstreamClient();
4915
4915
  const variant = WORKBUDDY_VARIANTS.find((v) => v.id === account.provider);
@@ -4974,6 +4974,25 @@ async function createAccountClient(account, config, attachments) {
4974
4974
  }
4975
4975
  };
4976
4976
  const usage = new TraeUsageClient({ credential, deviceId: async () => (await identity()).deviceId });
4977
+ if (account.provider === "trae") {
4978
+ const checkinUsage = new TraeUsageClient({
4979
+ credential,
4980
+ deviceId: async () => (await identity()).deviceId,
4981
+ fetchImpl: async (url, options) => {
4982
+ const response = await fetch(url, options);
4983
+ if (!response.ok) throw Object.assign(Error("checkin_http_error"), { status: response.status });
4984
+ if (String(url).endsWith("/status")) {
4985
+ const body = await response.clone().json();
4986
+ if (body.code !== void 0 && body.code !== 0 || typeof body.checked_in !== "boolean" || typeof body.did_checked_in !== "boolean") throw Object.assign(Error("checkin_status_rejected"), { status: 403 });
4987
+ }
4988
+ return response;
4989
+ }
4990
+ });
4991
+ checkin = {
4992
+ identity: async () => ({ account: (await credential()).userId, device: (await identity()).deviceId }),
4993
+ claim: (signal) => claimTraeCheckin(checkinUsage, signal)
4994
+ };
4995
+ }
4977
4996
  accountInfo = async (signal) => {
4978
4997
  const c = await credential();
4979
4998
  const login = {
@@ -5022,7 +5041,8 @@ async function createAccountClient(account, config, attachments) {
5022
5041
  const transport = createQoderTransport({
5023
5042
  region,
5024
5043
  resolvePat: getPat,
5025
- resolveMachineId: () => getMachineId([`${account.credentialFile}.machine-id`]),
5044
+ // Reuse the official CLI identity (or one persisted plugin seed) for this physical device.
5045
+ resolveMachineId: () => getMachineId(),
5026
5046
  ...attachments ? { attachments } : {}
5027
5047
  });
5028
5048
  const client = new QoderUpstreamClient({
@@ -5032,6 +5052,27 @@ async function createAccountClient(account, config, attachments) {
5032
5052
  transport,
5033
5053
  ...attachments ? { attachments } : {}
5034
5054
  });
5055
+ const checkinTransport = createQoderTransport({
5056
+ region,
5057
+ resolvePat: getPat,
5058
+ resolveMachineId: () => getMachineId(),
5059
+ fetch: async (url, options) => {
5060
+ const response = await fetch(url, options);
5061
+ if (!response.ok) {
5062
+ const restricted = [401, 403, 429].includes(response.status);
5063
+ throw new QoderLlmError(`checkin_http_${response.status}`, restricted ? "QUOTA" : "PROVIDER_ERROR", { status: response.status });
5064
+ }
5065
+ return response;
5066
+ }
5067
+ });
5068
+ checkin = {
5069
+ identity: async (signal) => ({ account: (await checkinTransport.readAccount({ signal })).profile.id }),
5070
+ claim: async (signal) => {
5071
+ const result = await checkinTransport.checkIn(signal);
5072
+ if (result.status !== "error") return { status: result.status };
5073
+ return { status: /401|403|429|rate.?limit|throttl|captcha|verify|verification|风控|验证|频繁|forbidden|unauthor|AUTH/i.test(result.message || "") ? "paused" : "uncertain" };
5074
+ }
5075
+ };
5035
5076
  accountInfo = async (signal) => {
5036
5077
  const result = await transport.readAccount({ force: true, signal });
5037
5078
  const buckets = [["\u4E2A\u4EBA\u5957\u9910", result.usage?.userQuota], ["\u9644\u52A0\u989D\u5EA6", result.usage?.addOnQuota], ["\u7EC4\u7EC7\u989D\u5EA6", result.usage?.orgResourcePackage]].filter(([, p]) => p).map(([name, p]) => ({ ...p, name }));
@@ -5052,17 +5093,33 @@ async function createAccountClient(account, config, attachments) {
5052
5093
  return {
5053
5094
  models: cachedModels(discover, config.catalogTtlMs),
5054
5095
  accountInfo,
5096
+ checkin,
5055
5097
  async chat(input, signal) {
5056
5098
  const result = await chat(input, signal);
5057
5099
  return result.ok ? preflightStream(result.response, signal) : result;
5058
5100
  }
5059
5101
  };
5060
5102
  }
5103
+ async function claimTraeCheckin(usage, signal) {
5104
+ try {
5105
+ const status = await usage.checkinStatus(signal);
5106
+ if (status.checkedIn) return { status: "already-claimed" };
5107
+ if (status.didCheckedIn) return { status: "device-used" };
5108
+ if (!status.enabled) return { status: "no-campaign" };
5109
+ const claim = await usage.claimCheckin(signal);
5110
+ if (claim.code === 9095) return { status: "device-used" };
5111
+ if (!claim.claimed) return { status: "paused" };
5112
+ return { status: "claimed", ...Number.isFinite(status.credits) ? { amount: status.credits + (status.extraCredits || 0) } : {} };
5113
+ } catch (e) {
5114
+ return { status: [401, 403, 429].includes(e.status) ? "paused" : "uncertain" };
5115
+ }
5116
+ }
5061
5117
 
5062
5118
  export {
5063
5119
  qoderPluginDataDir,
5064
5120
  jsonCredential,
5065
5121
  cachedModels,
5066
- createAccountClient
5122
+ createAccountClient,
5123
+ claimTraeCheckin
5067
5124
  };
5068
- //# sourceMappingURL=chunk-UFS7ZJKY.js.map
5125
+ //# sourceMappingURL=chunk-YUP77Q3A.js.map