galaxy-opc-plugin 0.2.6 → 0.2.8

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 @@
2
2
  "id": "galaxy-opc-plugin",
3
3
  "name": "OPC Platform",
4
4
  "description": "星环OPC中心 — 一人公司孵化与赋能平台",
5
- "version": "0.2.6",
5
+ "version": "0.2.8",
6
6
  "skills": ["./skills"],
7
7
  "configSchema": {
8
8
  "type": "object",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "galaxy-opc-plugin",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "星环 Galaxy OPC — 一人公司孵化与赋能平台 OpenClaw 插件",
5
5
  "keywords": [
6
6
  "openclaw",
@@ -59,7 +59,7 @@ function parseJson(body: string): Record<string, unknown> | null {
59
59
  export function registerCompanyRoutes(api: OpenClawPluginApi, db: OpcDatabase, gatewayToken?: string): void {
60
60
  const manager = new CompanyManager(db);
61
61
 
62
- api.registerHttpHandler(async (req, res) => {
62
+ const handler = async (req: IncomingMessage, res: ServerResponse): Promise<boolean> => {
63
63
  const rawUrl = req.url ?? "";
64
64
  const method = req.method?.toUpperCase() ?? "GET";
65
65
 
@@ -204,5 +204,27 @@ export function registerCompanyRoutes(api: OpenClawPluginApi, db: OpcDatabase, g
204
204
  sendError(res, err instanceof Error ? err.message : String(err), 500);
205
205
  return true;
206
206
  }
207
- });
207
+ };
208
+
209
+ const apiAny = api as unknown as {
210
+ registerHttpHandler?: (h: (req: IncomingMessage, res: ServerResponse) => Promise<boolean> | boolean) => void;
211
+ registerHttpRoute?: (r: { path: string | RegExp; handler: (req: IncomingMessage, res: ServerResponse) => void | Promise<void> }) => void;
212
+ };
213
+
214
+ if (typeof apiAny.registerHttpHandler === "function") {
215
+ apiAny.registerHttpHandler(handler);
216
+ } else if (typeof apiAny.registerHttpRoute === "function") {
217
+ apiAny.registerHttpRoute({
218
+ path: /^\/opc\/api\/companies(?:\/.*)?$/,
219
+ handler: async (req, res) => {
220
+ const handled = await handler(req, res);
221
+ if (!handled) {
222
+ res.writeHead(404, { "Content-Type": "application/json; charset=utf-8" });
223
+ res.end(JSON.stringify({ error: "Not found" }));
224
+ }
225
+ },
226
+ });
227
+ } else {
228
+ throw new Error("No compatible HTTP registration API found on OpenClaw plugin API");
229
+ }
208
230
  }
@@ -279,18 +279,18 @@ function classifyPaymentRisks(db: OpcDatabase, log: (msg: string) => void): void
279
279
  const today = new Date().toISOString().slice(0, 10);
280
280
 
281
281
  // 更新所有应收的逾期天数
282
- db.exec(
283
- `UPDATE opc_payments
284
- SET overdue_days = CAST((julianday('${today}') - julianday(due_date)) AS INTEGER)
285
- WHERE direction = 'receivable' AND status IN ('pending', 'partial', 'overdue') AND due_date != ''`,
286
- );
282
+ db.execute(
283
+ `UPDATE opc_payments
284
+ SET overdue_days = CAST((julianday('${today}') - julianday(due_date)) AS INTEGER)
285
+ WHERE direction = 'receivable' AND status IN ('pending', 'partial', 'overdue') AND due_date != ''`,
286
+ );
287
287
 
288
288
  // 更新风险等级
289
- db.exec(
290
- `UPDATE opc_payments
291
- SET risk_level = CASE
292
- WHEN overdue_days <= 7 THEN 'normal'
293
- WHEN overdue_days BETWEEN 8 AND 30 THEN 'warning'
289
+ db.execute(
290
+ `UPDATE opc_payments
291
+ SET risk_level = CASE
292
+ WHEN overdue_days <= 7 THEN 'normal'
293
+ WHEN overdue_days BETWEEN 8 AND 30 THEN 'warning'
294
294
  ELSE 'critical'
295
295
  END
296
296
  WHERE direction = 'receivable' AND status IN ('pending', 'partial', 'overdue')`,
@@ -3123,11 +3123,11 @@ function getCanvasJs(): string {
3123
3123
 
3124
3124
  /* ── Route registration ───────────────────────────────────── */
3125
3125
 
3126
- export function registerConfigUi(api: OpenClawPluginApi, db: OpcDatabase, gatewayToken?: string): void {
3126
+ export function registerConfigUi(api: OpenClawPluginApi, db: OpcDatabase, gatewayToken?: string): void {
3127
3127
  // 注册 Dashboard API 路由
3128
3128
  registerDashboardApiRoutes(api, db);
3129
3129
 
3130
- api.registerHttpHandler(async (req, res) => {
3130
+ const handler = async (req: IncomingMessage, res: ServerResponse): Promise<boolean> => {
3131
3131
  const rawUrl = req.url ?? "";
3132
3132
  const urlObj = new URL(rawUrl, "http://localhost");
3133
3133
  const pathname = urlObj.pathname;
@@ -4169,7 +4169,29 @@ export function registerConfigUi(api: OpenClawPluginApi, db: OpcDatabase, gatewa
4169
4169
  res.end(JSON.stringify({ error: err instanceof Error ? err.message : String(err) }));
4170
4170
  return true;
4171
4171
  }
4172
- });
4172
+ };
4173
+
4174
+ const apiAny = api as unknown as {
4175
+ registerHttpHandler?: (h: (req: IncomingMessage, res: ServerResponse) => Promise<boolean> | boolean) => void;
4176
+ registerHttpRoute?: (r: { path: string | RegExp; handler: (req: IncomingMessage, res: ServerResponse) => void | Promise<void> }) => void;
4177
+ };
4178
+
4179
+ if (typeof apiAny.registerHttpHandler === "function") {
4180
+ apiAny.registerHttpHandler(handler);
4181
+ } else if (typeof apiAny.registerHttpRoute === "function") {
4182
+ apiAny.registerHttpRoute({
4183
+ path: /^\/opc\/admin(?:\/.*)?$/,
4184
+ handler: async (req, res) => {
4185
+ const handled = await handler(req, res);
4186
+ if (!handled) {
4187
+ res.writeHead(404, { "Content-Type": "application/json; charset=utf-8" });
4188
+ res.end(JSON.stringify({ error: "Not found" }));
4189
+ }
4190
+ },
4191
+ });
4192
+ } else {
4193
+ throw new Error("No compatible HTTP registration API found on OpenClaw plugin API");
4194
+ }
4173
4195
 
4174
4196
  api.logger.info("opc: 已注册配置管理 UI (/opc/admin)");
4175
4197
  }
@@ -8,7 +8,7 @@
8
8
  import fs from "node:fs";
9
9
  import path from "node:path";
10
10
  import { fileURLToPath } from "node:url";
11
- import type { ServerResponse } from "node:http";
11
+ import type { IncomingMessage, ServerResponse } from "node:http";
12
12
  import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
13
13
 
14
14
  const __filename = fileURLToPath(import.meta.url);
@@ -262,7 +262,7 @@ export function registerLandingPage(api: OpenClawPluginApi): void {
262
262
  const homepageDir = path.resolve(__dirname, "../../../../opc-homepage");
263
263
  const homepageIndexPath = path.join(homepageDir, "index.html");
264
264
 
265
- api.registerHttpHandler(async (req, res) => {
265
+ const handler = async (req: IncomingMessage, res: ServerResponse): Promise<boolean> => {
266
266
  const rawUrl = req.url ?? "";
267
267
  const urlObj = new URL(rawUrl, "http://localhost");
268
268
  const pathname = urlObj.pathname;
@@ -313,7 +313,29 @@ export function registerLandingPage(api: OpenClawPluginApi): void {
313
313
  }
314
314
 
315
315
  return false;
316
- });
316
+ };
317
+
318
+ const apiAny = api as unknown as {
319
+ registerHttpHandler?: (h: (req: IncomingMessage, res: ServerResponse) => Promise<boolean> | boolean) => void;
320
+ registerHttpRoute?: (r: { path: string | RegExp; handler: (req: IncomingMessage, res: ServerResponse) => void | Promise<void> }) => void;
321
+ };
322
+
323
+ if (typeof apiAny.registerHttpHandler === "function") {
324
+ apiAny.registerHttpHandler(handler);
325
+ } else if (typeof apiAny.registerHttpRoute === "function") {
326
+ apiAny.registerHttpRoute({
327
+ path: /^\/$/,
328
+ handler: async (req, res) => {
329
+ const handled = await handler(req, res);
330
+ if (!handled) {
331
+ res.writeHead(404, { "Content-Type": "text/plain; charset=utf-8" });
332
+ res.end("Not found");
333
+ }
334
+ },
335
+ });
336
+ } else {
337
+ throw new Error("No compatible HTTP registration API found on OpenClaw plugin API");
338
+ }
317
339
 
318
340
  api.logger.info("opc: 已注册产品官网 (/)");
319
341
  }