@clawos-dev/clawd 0.2.219-beta.430.6b524a2 → 0.2.219

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.
Files changed (2) hide show
  1. package/dist/cli.cjs +77 -1
  2. package/package.json +1 -1
package/dist/cli.cjs CHANGED
@@ -54226,6 +54226,22 @@ var LoginFlow = class {
54226
54226
  } catch (err) {
54227
54227
  return { ok: false, reason: `user_info failed: ${err.message}` };
54228
54228
  }
54229
+ if (!identity.unionId) {
54230
+ return { ok: false, reason: "union_id missing from TTC user_info" };
54231
+ }
54232
+ try {
54233
+ await this.deps.upsertBinding({
54234
+ deviceId: this.deps.getDeviceId(),
54235
+ unionId: identity.unionId,
54236
+ displayName: identity.displayName,
54237
+ avatarUrl: identity.avatarUrl ?? null
54238
+ });
54239
+ } catch (err) {
54240
+ return {
54241
+ ok: false,
54242
+ reason: `device_binding upsert failed: ${err.message}`
54243
+ };
54244
+ }
54229
54245
  const expiresAtNum = params.expiresAt ? Number.parseInt(params.expiresAt, 10) : NaN;
54230
54246
  this.deps.store.write({
54231
54247
  identity,
@@ -54394,6 +54410,57 @@ async function centralListDevices(opts) {
54394
54410
  return out;
54395
54411
  }
54396
54412
 
54413
+ // src/feishu-auth/device-binding-client.ts
54414
+ var DeviceBindingClientError = class extends Error {
54415
+ constructor(code, message, cause) {
54416
+ super(message);
54417
+ this.code = code;
54418
+ this.cause = cause;
54419
+ this.name = "DeviceBindingClientError";
54420
+ }
54421
+ code;
54422
+ cause;
54423
+ };
54424
+ var DEFAULT_TIMEOUT_MS4 = 8e3;
54425
+ async function upsertDeviceBinding(opts) {
54426
+ const doFetch = opts.fetchImpl ?? fetch;
54427
+ const ac = new AbortController();
54428
+ const timer = setTimeout(() => ac.abort(), opts.timeoutMs ?? DEFAULT_TIMEOUT_MS4);
54429
+ const body = { unionId: opts.unionId };
54430
+ if (opts.avatarUrl != null) body.avatarUrl = opts.avatarUrl;
54431
+ let res;
54432
+ try {
54433
+ res = await doFetch(`${opts.apiUrl}/api/device-bindings/self`, {
54434
+ method: "PUT",
54435
+ signal: ac.signal,
54436
+ headers: {
54437
+ authorization: `Bearer ${opts.apiKey}`,
54438
+ "x-did": encodeURIComponent(opts.deviceId),
54439
+ "x-name": encodeURIComponent(opts.displayName),
54440
+ "content-type": "application/json"
54441
+ },
54442
+ body: JSON.stringify(body)
54443
+ });
54444
+ } catch (err) {
54445
+ clearTimeout(timer);
54446
+ throw new DeviceBindingClientError(
54447
+ "NETWORK",
54448
+ `network error: ${err.message}`,
54449
+ err
54450
+ );
54451
+ } finally {
54452
+ clearTimeout(timer);
54453
+ }
54454
+ if (!res.ok) {
54455
+ let detail = "";
54456
+ try {
54457
+ detail = JSON.stringify(await res.json());
54458
+ } catch {
54459
+ }
54460
+ throw new DeviceBindingClientError("API_ERROR", `HTTP ${res.status}: ${detail}`);
54461
+ }
54462
+ }
54463
+
54397
54464
  // src/feishu-auth/verify-token.ts
54398
54465
  var crypto14 = __toESM(require("crypto"), 1);
54399
54466
  var CONNECT_TOKEN_PREFIX = "clawdtk1";
@@ -59563,7 +59630,16 @@ async function startDaemon(config) {
59563
59630
  store: ownerIdentityStore,
59564
59631
  fetchUserInfo: (ttcToken) => fetchTtcUserInfo({ apiBase: TTC_HOSTS.api, token: ttcToken }),
59565
59632
  ttcAuthBase: TTC_HOSTS.auth,
59566
- getCallbackUrl: () => `http://127.0.0.1:${config.port}/auth/callback`
59633
+ getCallbackUrl: () => `http://127.0.0.1:${config.port}/auth/callback`,
59634
+ // device_bindings upsert(did ↔ 飞书 unionId 映射):
59635
+ // deviceId 从 auth.json 稳定读;apiUrl 走同一份 clawosApi;apiKey 复用 CLAWD_TICKETS_API_KEY。
59636
+ // 失败即登录失败(fail-hard,login-flow.spec §upsert 失败)。
59637
+ getDeviceId: () => authFile.deviceId,
59638
+ upsertBinding: (opts) => upsertDeviceBinding({
59639
+ apiUrl: config.clawosApi ?? DEFAULT_CLAWOS_API,
59640
+ apiKey: resolveClawdTicketsApiKey(),
59641
+ ...opts
59642
+ })
59567
59643
  });
59568
59644
  const visitorStore = createVisitorStore({ dir: config.dataDir });
59569
59645
  const exchangeVisitorToken = buildVisitorLogin({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clawos-dev/clawd",
3
- "version": "0.2.219-beta.430.6b524a2",
3
+ "version": "0.2.219",
4
4
  "description": "Standalone clawd daemon — Claude Code (and future Codex) session server over WebSocket",
5
5
  "type": "module",
6
6
  "license": "MIT",