csdn-im 0.1.8 → 0.1.9

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/dist/index.cjs CHANGED
@@ -4492,73 +4492,137 @@ var import_node_fs = require("fs");
4492
4492
  var import_node_module = require("module");
4493
4493
  var import_node_path = require("path");
4494
4494
  var import_node_url = require("url");
4495
- function findRequireAnchorPackageJson() {
4496
- let dir = process.cwd();
4497
- for (let i = 0; i < 8; i++) {
4498
- const pkg = (0, import_node_path.join)(dir, "package.json");
4499
- if ((0, import_node_fs.existsSync)(pkg)) return pkg;
4500
- const parent = (0, import_node_path.dirname)(dir);
4501
- if (parent === dir) break;
4502
- dir = parent;
4503
- }
4504
- throw new Error(
4505
- `${CSDN_LOG_TAG} loadOpenclawPluginSdk: no package.json found walking up from process.cwd(); cannot createRequire for openclaw fallback`
4506
- );
4507
- }
4508
- var OPENCLAW_SEARCH_ROOTS = [
4495
+ var NODE_MODULES_OPENCLAW = (0, import_node_path.join)("node_modules", "openclaw", "package.json");
4496
+ var LEGACY_RESOLVE_ROOTS = [
4509
4497
  process.cwd(),
4510
4498
  (0, import_node_path.join)(process.cwd(), ".."),
4511
4499
  (0, import_node_path.join)(process.cwd(), "..", ".."),
4512
4500
  (0, import_node_path.join)(process.cwd(), "packages", "csdn"),
4513
4501
  (0, import_node_path.join)(process.cwd(), "..", "packages", "csdn")
4514
4502
  ];
4515
- async function importOpenclawPluginSdkFromDisk() {
4516
- const require2 = (0, import_node_module.createRequire)(findRequireAnchorPackageJson());
4517
- for (const root of OPENCLAW_SEARCH_ROOTS) {
4518
- try {
4519
- const mainEntry = require2.resolve("openclaw", { paths: [root] });
4520
- const pkgRoot = (0, import_node_path.join)((0, import_node_path.dirname)(mainEntry), "..");
4521
- const sdkEntry = (0, import_node_path.join)(pkgRoot, "dist", "plugin-sdk", "index.js");
4522
- return await import((0, import_node_url.pathToFileURL)(sdkEntry).href);
4523
- } catch {
4503
+ function tryResolveOpenclawRootWithRequire(anchorFile) {
4504
+ try {
4505
+ const req = (0, import_node_module.createRequire)(anchorFile);
4506
+ let d = (0, import_node_path.dirname)(req.resolve("openclaw"));
4507
+ for (let i = 0; i < 8; i++) {
4508
+ if ((0, import_node_fs.existsSync)((0, import_node_path.join)(d, "package.json")) && (0, import_node_fs.existsSync)((0, import_node_path.join)(d, "dist", "plugin-sdk", "index.js"))) {
4509
+ return d;
4510
+ }
4511
+ const parent = (0, import_node_path.dirname)(d);
4512
+ if (parent === d) break;
4513
+ d = parent;
4524
4514
  }
4515
+ } catch {
4516
+ return void 0;
4525
4517
  }
4526
- throw new Error(`${CSDN_LOG_TAG} could not resolve openclaw from disk`);
4518
+ return void 0;
4527
4519
  }
4528
- async function importOpenclawReplyRuntimeFromDisk() {
4529
- const require2 = (0, import_node_module.createRequire)(findRequireAnchorPackageJson());
4530
- for (const root of OPENCLAW_SEARCH_ROOTS) {
4531
- try {
4532
- const mainEntry = require2.resolve("openclaw", { paths: [root] });
4533
- const pkgRoot = (0, import_node_path.join)((0, import_node_path.dirname)(mainEntry), "..");
4534
- const entry = (0, import_node_path.join)(pkgRoot, "dist", "plugin-sdk", "reply-runtime.js");
4535
- return await import((0, import_node_url.pathToFileURL)(entry).href);
4536
- } catch {
4520
+ function scanUpFromEntryMain(main) {
4521
+ const fromEntry = tryResolveOpenclawRootWithRequire(main);
4522
+ if (fromEntry) return fromEntry;
4523
+ let dir = (0, import_node_path.dirname)(main);
4524
+ for (let i = 0; i < 48; i++) {
4525
+ const pkgJson = (0, import_node_path.join)(dir, "package.json");
4526
+ if ((0, import_node_fs.existsSync)(pkgJson)) {
4527
+ const hit = tryResolveOpenclawRootWithRequire(pkgJson);
4528
+ if (hit) return hit;
4529
+ }
4530
+ const direct = (0, import_node_path.join)(dir, NODE_MODULES_OPENCLAW);
4531
+ if ((0, import_node_fs.existsSync)(direct)) return (0, import_node_path.dirname)(direct);
4532
+ const parent = (0, import_node_path.dirname)(dir);
4533
+ if (parent === dir) break;
4534
+ dir = parent;
4535
+ }
4536
+ return void 0;
4537
+ }
4538
+ function listEntryAnchorScripts() {
4539
+ const out = [];
4540
+ const a = process.argv[1];
4541
+ if (a && (0, import_node_fs.existsSync)(a)) out.push(a);
4542
+ try {
4543
+ const mainFn = typeof require !== "undefined" ? require.main?.filename : void 0;
4544
+ if (mainFn && (0, import_node_fs.existsSync)(mainFn) && mainFn !== a) out.push(mainFn);
4545
+ } catch {
4546
+ }
4547
+ return out;
4548
+ }
4549
+ function resolveOpenclawPackageRoot() {
4550
+ for (const main of listEntryAnchorScripts()) {
4551
+ const hit = scanUpFromEntryMain(main);
4552
+ if (hit) return hit;
4553
+ }
4554
+ let cwd = process.cwd();
4555
+ for (let i = 0; i < 48; i++) {
4556
+ const direct = (0, import_node_path.join)(cwd, NODE_MODULES_OPENCLAW);
4557
+ if ((0, import_node_fs.existsSync)(direct)) return (0, import_node_path.dirname)(direct);
4558
+ const parent = (0, import_node_path.dirname)(cwd);
4559
+ if (parent === cwd) break;
4560
+ cwd = parent;
4561
+ }
4562
+ const delimiter = process.platform === "win32" ? ";" : ":";
4563
+ for (const raw of (process.env.NODE_PATH ?? "").split(delimiter)) {
4564
+ const np = raw.trim();
4565
+ if (!np) continue;
4566
+ const p = (0, import_node_path.join)(np, "openclaw", "package.json");
4567
+ if ((0, import_node_fs.existsSync)(p)) return (0, import_node_path.dirname)(p);
4568
+ }
4569
+ let anchor;
4570
+ let d = process.cwd();
4571
+ for (let i = 0; i < 8; i++) {
4572
+ const pkg = (0, import_node_path.join)(d, "package.json");
4573
+ if ((0, import_node_fs.existsSync)(pkg)) {
4574
+ anchor = pkg;
4575
+ break;
4576
+ }
4577
+ const parent = (0, import_node_path.dirname)(d);
4578
+ if (parent === d) break;
4579
+ d = parent;
4580
+ }
4581
+ if (anchor) {
4582
+ const req = (0, import_node_module.createRequire)(anchor);
4583
+ for (const root of LEGACY_RESOLVE_ROOTS) {
4584
+ try {
4585
+ const mainEntry = req.resolve("openclaw", { paths: [root] });
4586
+ return (0, import_node_path.join)((0, import_node_path.dirname)(mainEntry), "..");
4587
+ } catch {
4588
+ }
4537
4589
  }
4538
4590
  }
4539
- throw new Error(`${CSDN_LOG_TAG} could not resolve openclaw reply-runtime from disk`);
4591
+ return void 0;
4592
+ }
4593
+ async function importPluginSdkFromRoot(root) {
4594
+ const sdkEntry = (0, import_node_path.join)(root, "dist", "plugin-sdk", "index.js");
4595
+ if (!(0, import_node_fs.existsSync)(sdkEntry)) {
4596
+ throw new Error(`${CSDN_LOG_TAG} openclaw plugin-sdk not found at ${sdkEntry}`);
4597
+ }
4598
+ return await import((0, import_node_url.pathToFileURL)(sdkEntry).href);
4599
+ }
4600
+ async function importReplyRuntimeFromRoot(root) {
4601
+ const entry = (0, import_node_path.join)(root, "dist", "plugin-sdk", "reply-runtime.js");
4602
+ if (!(0, import_node_fs.existsSync)(entry)) {
4603
+ throw new Error(`${CSDN_LOG_TAG} openclaw reply-runtime not found at ${entry}`);
4604
+ }
4605
+ return await import((0, import_node_url.pathToFileURL)(entry).href);
4540
4606
  }
4541
4607
  async function loadOpenclawReplyRuntime() {
4542
- try {
4543
- return await import("openclaw/plugin-sdk/reply-runtime");
4544
- } catch (first) {
4608
+ const root = resolveOpenclawPackageRoot();
4609
+ if (root) {
4545
4610
  try {
4546
- return await importOpenclawReplyRuntimeFromDisk();
4611
+ return await importReplyRuntimeFromRoot(root);
4547
4612
  } catch {
4548
- throw first;
4549
4613
  }
4550
4614
  }
4615
+ return await import("openclaw/plugin-sdk/reply-runtime");
4551
4616
  }
4552
4617
  async function loadOpenclawPluginSdk() {
4553
- try {
4554
- return await import("openclaw/plugin-sdk");
4555
- } catch (first) {
4618
+ const root = resolveOpenclawPackageRoot();
4619
+ if (root) {
4556
4620
  try {
4557
- return await importOpenclawPluginSdkFromDisk();
4621
+ return await importPluginSdkFromRoot(root);
4558
4622
  } catch {
4559
- throw first;
4560
4623
  }
4561
4624
  }
4625
+ return await import("openclaw/plugin-sdk");
4562
4626
  }
4563
4627
 
4564
4628
  // src/outbound.ts
package/dist/index.js CHANGED
@@ -1,4 +1,10 @@
1
1
  var __defProp = Object.defineProperty;
2
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
+ }) : x)(function(x) {
5
+ if (typeof require !== "undefined") return require.apply(this, arguments);
6
+ throw Error('Dynamic require of "' + x + '" is not supported');
7
+ });
2
8
  var __export = (target, all) => {
3
9
  for (var name in all)
4
10
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -4461,73 +4467,137 @@ import { existsSync } from "fs";
4461
4467
  import { createRequire } from "module";
4462
4468
  import { dirname, join } from "path";
4463
4469
  import { pathToFileURL } from "url";
4464
- function findRequireAnchorPackageJson() {
4465
- let dir = process.cwd();
4466
- for (let i = 0; i < 8; i++) {
4467
- const pkg = join(dir, "package.json");
4468
- if (existsSync(pkg)) return pkg;
4469
- const parent = dirname(dir);
4470
- if (parent === dir) break;
4471
- dir = parent;
4472
- }
4473
- throw new Error(
4474
- `${CSDN_LOG_TAG} loadOpenclawPluginSdk: no package.json found walking up from process.cwd(); cannot createRequire for openclaw fallback`
4475
- );
4476
- }
4477
- var OPENCLAW_SEARCH_ROOTS = [
4470
+ var NODE_MODULES_OPENCLAW = join("node_modules", "openclaw", "package.json");
4471
+ var LEGACY_RESOLVE_ROOTS = [
4478
4472
  process.cwd(),
4479
4473
  join(process.cwd(), ".."),
4480
4474
  join(process.cwd(), "..", ".."),
4481
4475
  join(process.cwd(), "packages", "csdn"),
4482
4476
  join(process.cwd(), "..", "packages", "csdn")
4483
4477
  ];
4484
- async function importOpenclawPluginSdkFromDisk() {
4485
- const require2 = createRequire(findRequireAnchorPackageJson());
4486
- for (const root of OPENCLAW_SEARCH_ROOTS) {
4487
- try {
4488
- const mainEntry = require2.resolve("openclaw", { paths: [root] });
4489
- const pkgRoot = join(dirname(mainEntry), "..");
4490
- const sdkEntry = join(pkgRoot, "dist", "plugin-sdk", "index.js");
4491
- return await import(pathToFileURL(sdkEntry).href);
4492
- } catch {
4478
+ function tryResolveOpenclawRootWithRequire(anchorFile) {
4479
+ try {
4480
+ const req = createRequire(anchorFile);
4481
+ let d = dirname(req.resolve("openclaw"));
4482
+ for (let i = 0; i < 8; i++) {
4483
+ if (existsSync(join(d, "package.json")) && existsSync(join(d, "dist", "plugin-sdk", "index.js"))) {
4484
+ return d;
4485
+ }
4486
+ const parent = dirname(d);
4487
+ if (parent === d) break;
4488
+ d = parent;
4493
4489
  }
4490
+ } catch {
4491
+ return void 0;
4494
4492
  }
4495
- throw new Error(`${CSDN_LOG_TAG} could not resolve openclaw from disk`);
4493
+ return void 0;
4496
4494
  }
4497
- async function importOpenclawReplyRuntimeFromDisk() {
4498
- const require2 = createRequire(findRequireAnchorPackageJson());
4499
- for (const root of OPENCLAW_SEARCH_ROOTS) {
4500
- try {
4501
- const mainEntry = require2.resolve("openclaw", { paths: [root] });
4502
- const pkgRoot = join(dirname(mainEntry), "..");
4503
- const entry = join(pkgRoot, "dist", "plugin-sdk", "reply-runtime.js");
4504
- return await import(pathToFileURL(entry).href);
4505
- } catch {
4495
+ function scanUpFromEntryMain(main) {
4496
+ const fromEntry = tryResolveOpenclawRootWithRequire(main);
4497
+ if (fromEntry) return fromEntry;
4498
+ let dir = dirname(main);
4499
+ for (let i = 0; i < 48; i++) {
4500
+ const pkgJson = join(dir, "package.json");
4501
+ if (existsSync(pkgJson)) {
4502
+ const hit = tryResolveOpenclawRootWithRequire(pkgJson);
4503
+ if (hit) return hit;
4504
+ }
4505
+ const direct = join(dir, NODE_MODULES_OPENCLAW);
4506
+ if (existsSync(direct)) return dirname(direct);
4507
+ const parent = dirname(dir);
4508
+ if (parent === dir) break;
4509
+ dir = parent;
4510
+ }
4511
+ return void 0;
4512
+ }
4513
+ function listEntryAnchorScripts() {
4514
+ const out = [];
4515
+ const a = process.argv[1];
4516
+ if (a && existsSync(a)) out.push(a);
4517
+ try {
4518
+ const mainFn = typeof __require !== "undefined" ? __require.main?.filename : void 0;
4519
+ if (mainFn && existsSync(mainFn) && mainFn !== a) out.push(mainFn);
4520
+ } catch {
4521
+ }
4522
+ return out;
4523
+ }
4524
+ function resolveOpenclawPackageRoot() {
4525
+ for (const main of listEntryAnchorScripts()) {
4526
+ const hit = scanUpFromEntryMain(main);
4527
+ if (hit) return hit;
4528
+ }
4529
+ let cwd = process.cwd();
4530
+ for (let i = 0; i < 48; i++) {
4531
+ const direct = join(cwd, NODE_MODULES_OPENCLAW);
4532
+ if (existsSync(direct)) return dirname(direct);
4533
+ const parent = dirname(cwd);
4534
+ if (parent === cwd) break;
4535
+ cwd = parent;
4536
+ }
4537
+ const delimiter = process.platform === "win32" ? ";" : ":";
4538
+ for (const raw of (process.env.NODE_PATH ?? "").split(delimiter)) {
4539
+ const np = raw.trim();
4540
+ if (!np) continue;
4541
+ const p = join(np, "openclaw", "package.json");
4542
+ if (existsSync(p)) return dirname(p);
4543
+ }
4544
+ let anchor;
4545
+ let d = process.cwd();
4546
+ for (let i = 0; i < 8; i++) {
4547
+ const pkg = join(d, "package.json");
4548
+ if (existsSync(pkg)) {
4549
+ anchor = pkg;
4550
+ break;
4506
4551
  }
4552
+ const parent = dirname(d);
4553
+ if (parent === d) break;
4554
+ d = parent;
4507
4555
  }
4508
- throw new Error(`${CSDN_LOG_TAG} could not resolve openclaw reply-runtime from disk`);
4556
+ if (anchor) {
4557
+ const req = createRequire(anchor);
4558
+ for (const root of LEGACY_RESOLVE_ROOTS) {
4559
+ try {
4560
+ const mainEntry = req.resolve("openclaw", { paths: [root] });
4561
+ return join(dirname(mainEntry), "..");
4562
+ } catch {
4563
+ }
4564
+ }
4565
+ }
4566
+ return void 0;
4567
+ }
4568
+ async function importPluginSdkFromRoot(root) {
4569
+ const sdkEntry = join(root, "dist", "plugin-sdk", "index.js");
4570
+ if (!existsSync(sdkEntry)) {
4571
+ throw new Error(`${CSDN_LOG_TAG} openclaw plugin-sdk not found at ${sdkEntry}`);
4572
+ }
4573
+ return await import(pathToFileURL(sdkEntry).href);
4574
+ }
4575
+ async function importReplyRuntimeFromRoot(root) {
4576
+ const entry = join(root, "dist", "plugin-sdk", "reply-runtime.js");
4577
+ if (!existsSync(entry)) {
4578
+ throw new Error(`${CSDN_LOG_TAG} openclaw reply-runtime not found at ${entry}`);
4579
+ }
4580
+ return await import(pathToFileURL(entry).href);
4509
4581
  }
4510
4582
  async function loadOpenclawReplyRuntime() {
4511
- try {
4512
- return await import("openclaw/plugin-sdk/reply-runtime");
4513
- } catch (first) {
4583
+ const root = resolveOpenclawPackageRoot();
4584
+ if (root) {
4514
4585
  try {
4515
- return await importOpenclawReplyRuntimeFromDisk();
4586
+ return await importReplyRuntimeFromRoot(root);
4516
4587
  } catch {
4517
- throw first;
4518
4588
  }
4519
4589
  }
4590
+ return await import("openclaw/plugin-sdk/reply-runtime");
4520
4591
  }
4521
4592
  async function loadOpenclawPluginSdk() {
4522
- try {
4523
- return await import("openclaw/plugin-sdk");
4524
- } catch (first) {
4593
+ const root = resolveOpenclawPackageRoot();
4594
+ if (root) {
4525
4595
  try {
4526
- return await importOpenclawPluginSdkFromDisk();
4596
+ return await importPluginSdkFromRoot(root);
4527
4597
  } catch {
4528
- throw first;
4529
4598
  }
4530
4599
  }
4600
+ return await import("openclaw/plugin-sdk");
4531
4601
  }
4532
4602
 
4533
4603
  // src/outbound.ts
@@ -10,7 +10,7 @@
10
10
  },
11
11
  "apiUrl": {
12
12
  "type": "string",
13
- "default": "https://test-msg.csdn.net/claw",
13
+ "default": "https://msg.csdn.net/claw",
14
14
  "description": "notification-claw 服务根 URL(不含路径),见 docs/ClawBot接口定义.md"
15
15
  },
16
16
  "token": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "csdn-im",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "type": "module",
5
5
  "description": "OpenClaw channel plugin for CSDN IM",
6
6
  "license": "MIT",