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

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 +78 -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,58 @@ 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
+ "x-scene": "daemon",
54441
+ "content-type": "application/json"
54442
+ },
54443
+ body: JSON.stringify(body)
54444
+ });
54445
+ } catch (err) {
54446
+ clearTimeout(timer);
54447
+ throw new DeviceBindingClientError(
54448
+ "NETWORK",
54449
+ `network error: ${err.message}`,
54450
+ err
54451
+ );
54452
+ } finally {
54453
+ clearTimeout(timer);
54454
+ }
54455
+ if (!res.ok) {
54456
+ let detail = "";
54457
+ try {
54458
+ detail = JSON.stringify(await res.json());
54459
+ } catch {
54460
+ }
54461
+ throw new DeviceBindingClientError("API_ERROR", `HTTP ${res.status}: ${detail}`);
54462
+ }
54463
+ }
54464
+
54397
54465
  // src/feishu-auth/verify-token.ts
54398
54466
  var crypto14 = __toESM(require("crypto"), 1);
54399
54467
  var CONNECT_TOKEN_PREFIX = "clawdtk1";
@@ -59563,7 +59631,16 @@ async function startDaemon(config) {
59563
59631
  store: ownerIdentityStore,
59564
59632
  fetchUserInfo: (ttcToken) => fetchTtcUserInfo({ apiBase: TTC_HOSTS.api, token: ttcToken }),
59565
59633
  ttcAuthBase: TTC_HOSTS.auth,
59566
- getCallbackUrl: () => `http://127.0.0.1:${config.port}/auth/callback`
59634
+ getCallbackUrl: () => `http://127.0.0.1:${config.port}/auth/callback`,
59635
+ // device_bindings upsert(did ↔ 飞书 unionId 映射):
59636
+ // deviceId 从 auth.json 稳定读;apiUrl 走同一份 clawosApi;apiKey 复用 CLAWD_TICKETS_API_KEY。
59637
+ // 失败即登录失败(fail-hard,login-flow.spec §upsert 失败)。
59638
+ getDeviceId: () => authFile.deviceId,
59639
+ upsertBinding: (opts) => upsertDeviceBinding({
59640
+ apiUrl: config.clawosApi ?? DEFAULT_CLAWOS_API,
59641
+ apiKey: resolveClawdTicketsApiKey(),
59642
+ ...opts
59643
+ })
59567
59644
  });
59568
59645
  const visitorStore = createVisitorStore({ dir: config.dataDir });
59569
59646
  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.220-beta.431.c9364d8",
4
4
  "description": "Standalone clawd daemon — Claude Code (and future Codex) session server over WebSocket",
5
5
  "type": "module",
6
6
  "license": "MIT",