@ycodium-ai/plugin-im 0.2.2990 → 0.2.2992

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/index.js +118 -116
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -130279,121 +130279,6 @@ var resultUnknown = (error) => error instanceof ConsoleError && (error.kind ===
130279
130279
  var isOwnerDenied = (error) => error.status === 403 && error.code === 10003;
130280
130280
  var isRecoverable = (error) => error instanceof ConsoleError && (error.kind === "api" || error.kind === "http" || error.kind === "protocol") && error.status !== 401 && error.status !== 403;
130281
130281
 
130282
- // src/lark/setup/cookieJar.ts
130283
- var MAX_REDIRECT_HOPS = 10;
130284
- var parseSetCookie = (responseUrl, header) => {
130285
- const url = new URL(responseUrl);
130286
- const parts = header.split(";").map((part) => part.trim()).filter((part) => part !== "");
130287
- const first = parts.shift();
130288
- if (first === void 0) return null;
130289
- const eq = first.indexOf("=");
130290
- if (eq <= 0) return null;
130291
- let domain = url.hostname;
130292
- let path = "/";
130293
- let secure = false;
130294
- let hostOnly = true;
130295
- let expiresAt;
130296
- for (const part of parts) {
130297
- const at = part.indexOf("=");
130298
- const key = (at >= 0 ? part.slice(0, at) : part).trim().toLowerCase();
130299
- const value2 = at >= 0 ? part.slice(at + 1).trim() : "";
130300
- if (key === "domain" && value2 !== "") {
130301
- domain = value2.replace(/^\./, "").toLowerCase();
130302
- hostOnly = false;
130303
- } else if (key === "path" && value2 !== "") path = value2;
130304
- else if (key === "secure") secure = true;
130305
- else if (key === "expires" && value2 !== "") {
130306
- const parsed = Date.parse(value2);
130307
- if (Number.isFinite(parsed)) expiresAt = parsed;
130308
- } else if (key === "max-age" && value2 !== "") {
130309
- const seconds = Number(value2);
130310
- if (Number.isFinite(seconds)) expiresAt = Date.now() + seconds * 1e3;
130311
- }
130312
- }
130313
- return {
130314
- name: first.slice(0, eq),
130315
- value: first.slice(eq + 1),
130316
- domain,
130317
- path,
130318
- secure,
130319
- hostOnly,
130320
- expiresAt
130321
- };
130322
- };
130323
- var domainMatches = (hostname, cookie) => {
130324
- const host = hostname.toLowerCase();
130325
- return cookie.hostOnly ? host === cookie.domain : host === cookie.domain || host.endsWith(`.${cookie.domain}`);
130326
- };
130327
- var pathMatches = (requestPath, cookiePath) => {
130328
- if (requestPath === cookiePath) return true;
130329
- if (!requestPath.startsWith(cookiePath)) return false;
130330
- return cookiePath.endsWith("/") || requestPath[cookiePath.length] === "/";
130331
- };
130332
- var makeCookieJar = (onSecret) => {
130333
- let cookies = [];
130334
- const prune = () => {
130335
- const now = Date.now();
130336
- cookies = cookies.filter((cookie) => cookie.expiresAt === void 0 || cookie.expiresAt > now);
130337
- };
130338
- const headerFor = (requestUrl) => {
130339
- prune();
130340
- const url = new URL(requestUrl);
130341
- return cookies.filter(
130342
- (cookie) => (!cookie.secure || url.protocol === "https:") && domainMatches(url.hostname, cookie) && pathMatches(url.pathname || "/", cookie.path)
130343
- ).sort((a, b) => b.path.length - a.path.length).map((cookie) => `${cookie.name}=${cookie.value}`).join("; ");
130344
- };
130345
- const absorb = (responseUrl, headers) => {
130346
- for (const raw of headers.getSetCookie()) {
130347
- const cookie = parseSetCookie(responseUrl, raw);
130348
- if (cookie === null) continue;
130349
- onSecret?.(cookie.value);
130350
- cookies = cookies.filter(
130351
- (existing) => !(existing.name === cookie.name && existing.domain === cookie.domain && existing.path === cookie.path)
130352
- );
130353
- if (cookie.expiresAt === void 0 || cookie.expiresAt > Date.now()) cookies.push(cookie);
130354
- }
130355
- };
130356
- return {
130357
- fetch: async (fetcher, url, init = {}) => {
130358
- let current = url;
130359
- let method = init.method ?? "GET";
130360
- let body = init.body;
130361
- let referer;
130362
- for (let hop = 0; hop <= MAX_REDIRECT_HOPS; hop += 1) {
130363
- const headers = new Headers(init.headers);
130364
- const cookie = headerFor(current);
130365
- if (cookie !== "") headers.set("cookie", cookie);
130366
- if (!headers.has("user-agent")) headers.set("user-agent", BROWSER_USER_AGENT);
130367
- if (referer !== void 0 && !headers.has("referer")) headers.set("referer", referer);
130368
- const response = await fetcher(current, {
130369
- ...init,
130370
- method,
130371
- headers,
130372
- ...body === void 0 ? {} : { body },
130373
- redirect: "manual"
130374
- });
130375
- absorb(current, response.headers);
130376
- const location = response.headers.get("location");
130377
- if (response.status >= 300 && response.status < 400 && location !== null) {
130378
- referer = current;
130379
- current = new URL(location, current).toString();
130380
- if ([301, 302, 303].includes(response.status) && method !== "GET") {
130381
- method = "GET";
130382
- body = void 0;
130383
- }
130384
- continue;
130385
- }
130386
- return { response, finalUrl: current };
130387
- }
130388
- throw new Error("too many redirects");
130389
- },
130390
- size: () => cookies.length,
130391
- clear: () => {
130392
- cookies = [];
130393
- }
130394
- };
130395
- };
130396
-
130397
130282
  // src/lark/setup/qrLogin.ts
130398
130283
  var QrLoginError = class extends Error {
130399
130284
  reason;
@@ -130560,7 +130445,122 @@ var makeRedactor = () => {
130560
130445
  };
130561
130446
  };
130562
130447
 
130563
- // src/lark/setup/setupFlow.ts
130448
+ // src/lark/setup/cookieJar.ts
130449
+ var MAX_REDIRECT_HOPS = 10;
130450
+ var parseSetCookie = (responseUrl, header) => {
130451
+ const url = new URL(responseUrl);
130452
+ const parts = header.split(";").map((part) => part.trim()).filter((part) => part !== "");
130453
+ const first = parts.shift();
130454
+ if (first === void 0) return null;
130455
+ const eq = first.indexOf("=");
130456
+ if (eq <= 0) return null;
130457
+ let domain = url.hostname;
130458
+ let path = "/";
130459
+ let secure = false;
130460
+ let hostOnly = true;
130461
+ let expiresAt;
130462
+ for (const part of parts) {
130463
+ const at = part.indexOf("=");
130464
+ const key = (at >= 0 ? part.slice(0, at) : part).trim().toLowerCase();
130465
+ const value2 = at >= 0 ? part.slice(at + 1).trim() : "";
130466
+ if (key === "domain" && value2 !== "") {
130467
+ domain = value2.replace(/^\./, "").toLowerCase();
130468
+ hostOnly = false;
130469
+ } else if (key === "path" && value2 !== "") path = value2;
130470
+ else if (key === "secure") secure = true;
130471
+ else if (key === "expires" && value2 !== "") {
130472
+ const parsed = Date.parse(value2);
130473
+ if (Number.isFinite(parsed)) expiresAt = parsed;
130474
+ } else if (key === "max-age" && value2 !== "") {
130475
+ const seconds = Number(value2);
130476
+ if (Number.isFinite(seconds)) expiresAt = Date.now() + seconds * 1e3;
130477
+ }
130478
+ }
130479
+ return {
130480
+ name: first.slice(0, eq),
130481
+ value: first.slice(eq + 1),
130482
+ domain,
130483
+ path,
130484
+ secure,
130485
+ hostOnly,
130486
+ expiresAt
130487
+ };
130488
+ };
130489
+ var domainMatches = (hostname, cookie) => {
130490
+ const host = hostname.toLowerCase();
130491
+ return cookie.hostOnly ? host === cookie.domain : host === cookie.domain || host.endsWith(`.${cookie.domain}`);
130492
+ };
130493
+ var pathMatches = (requestPath, cookiePath) => {
130494
+ if (requestPath === cookiePath) return true;
130495
+ if (!requestPath.startsWith(cookiePath)) return false;
130496
+ return cookiePath.endsWith("/") || requestPath[cookiePath.length] === "/";
130497
+ };
130498
+ var makeCookieJar = (onSecret) => {
130499
+ let cookies = [];
130500
+ const prune = () => {
130501
+ const now = Date.now();
130502
+ cookies = cookies.filter((cookie) => cookie.expiresAt === void 0 || cookie.expiresAt > now);
130503
+ };
130504
+ const headerFor = (requestUrl) => {
130505
+ prune();
130506
+ const url = new URL(requestUrl);
130507
+ return cookies.filter(
130508
+ (cookie) => (!cookie.secure || url.protocol === "https:") && domainMatches(url.hostname, cookie) && pathMatches(url.pathname || "/", cookie.path)
130509
+ ).sort((a, b) => b.path.length - a.path.length).map((cookie) => `${cookie.name}=${cookie.value}`).join("; ");
130510
+ };
130511
+ const absorb = (responseUrl, headers) => {
130512
+ for (const raw of headers.getSetCookie()) {
130513
+ const cookie = parseSetCookie(responseUrl, raw);
130514
+ if (cookie === null) continue;
130515
+ onSecret?.(cookie.value);
130516
+ cookies = cookies.filter(
130517
+ (existing) => !(existing.name === cookie.name && existing.domain === cookie.domain && existing.path === cookie.path)
130518
+ );
130519
+ if (cookie.expiresAt === void 0 || cookie.expiresAt > Date.now()) cookies.push(cookie);
130520
+ }
130521
+ };
130522
+ return {
130523
+ fetch: async (fetcher, url, init = {}) => {
130524
+ let current = url;
130525
+ let method = init.method ?? "GET";
130526
+ let body = init.body;
130527
+ let referer;
130528
+ for (let hop = 0; hop <= MAX_REDIRECT_HOPS; hop += 1) {
130529
+ const headers = new Headers(init.headers);
130530
+ const cookie = headerFor(current);
130531
+ if (cookie !== "") headers.set("cookie", cookie);
130532
+ if (!headers.has("user-agent")) headers.set("user-agent", BROWSER_USER_AGENT);
130533
+ if (referer !== void 0 && !headers.has("referer")) headers.set("referer", referer);
130534
+ const response = await fetcher(current, {
130535
+ ...init,
130536
+ method,
130537
+ headers,
130538
+ ...body === void 0 ? {} : { body },
130539
+ redirect: "manual"
130540
+ });
130541
+ absorb(current, response.headers);
130542
+ const location = response.headers.get("location");
130543
+ if (response.status >= 300 && response.status < 400 && location !== null) {
130544
+ referer = current;
130545
+ current = new URL(location, current).toString();
130546
+ if ([301, 302, 303].includes(response.status) && method !== "GET") {
130547
+ method = "GET";
130548
+ body = void 0;
130549
+ }
130550
+ continue;
130551
+ }
130552
+ return { response, finalUrl: current };
130553
+ }
130554
+ throw new Error("too many redirects");
130555
+ },
130556
+ size: () => cookies.length,
130557
+ clear: () => {
130558
+ cookies = [];
130559
+ }
130560
+ };
130561
+ };
130562
+
130563
+ // src/lark/setup/setupFlowModel.ts
130564
130564
  var SETUP_KEYS = {
130565
130565
  statusWaiting: "setup.status.waiting",
130566
130566
  statusScanned: "setup.status.scanned",
@@ -130642,6 +130642,8 @@ var listApps = async (client) => {
130642
130642
  }
130643
130643
  return out;
130644
130644
  };
130645
+
130646
+ // src/lark/setup/setupFlow.ts
130645
130647
  var createSetupRunner = (deps) => {
130646
130648
  const retryWindowMs = deps.sessionRetryWindowMs ?? SESSION_RETRY_WINDOW_MS;
130647
130649
  let running = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ycodium-ai/plugin-im",
3
- "version": "0.2.2990",
3
+ "version": "0.2.2992",
4
4
  "description": "Talk to your agents from Telegram, WeCom, Lark, or WeChat (experimental).",
5
5
  "keywords": [
6
6
  "im",
@@ -32,7 +32,7 @@
32
32
  "markdown-it": "^15.0.2",
33
33
  "react": "19.2.6",
34
34
  "vite-plus": "0.2.2",
35
- "@ycodium-ai/plugin-api": "0.2.2990"
35
+ "@ycodium-ai/plugin-api": "0.2.2992"
36
36
  },
37
37
  "ycodium": {
38
38
  "plugin": "./dist/index.js",