@lakphy/local-router 0.4.0-beta.2 → 0.4.0-beta.3

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.
@@ -5,8 +5,8 @@
5
5
  <link rel="icon" type="image/svg+xml" href="/vite.svg" />
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
7
  <title>web</title>
8
- <script type="module" crossorigin src="/admin/assets/index-DuaLtWlv.js"></script>
9
- <link rel="stylesheet" crossorigin href="/admin/assets/index-RuflkSNT.css">
8
+ <script type="module" crossorigin src="/admin/assets/index-CAs_-9_V.js"></script>
9
+ <link rel="stylesheet" crossorigin href="/admin/assets/index-224RFv8D.css">
10
10
  </head>
11
11
  <body>
12
12
  <div id="root"></div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lakphy/local-router",
3
- "version": "0.4.0-beta.2",
3
+ "version": "0.4.0-beta.3",
4
4
  "packageManager": "bun@1.2.0",
5
5
  "workspaces": [
6
6
  "web"
@@ -16,10 +16,14 @@
16
16
  "bin": {
17
17
  "local-router": "dist/cli.js"
18
18
  },
19
+ "exports": {
20
+ "./plugin": "./src/plugin.ts"
21
+ },
19
22
  "files": [
20
23
  "dist",
21
24
  "config.schema.json",
22
- "README.md"
25
+ "README.md",
26
+ "src/plugin.ts"
23
27
  ],
24
28
  "bun": {
25
29
  "target": "bun",
package/src/plugin.ts ADDED
@@ -0,0 +1,64 @@
1
+ /**
2
+ * 插件体系核心类型定义。
3
+ *
4
+ * 洋葱模型:请求阶段正序执行(外→内),响应阶段逆序执行(内→外)。
5
+ */
6
+
7
+ /** 插件上下文(只读,传递给每个 handler) */
8
+ export interface PluginContext {
9
+ requestId: string;
10
+ provider: string;
11
+ modelIn: string;
12
+ modelOut: string;
13
+ routeType: string;
14
+ isStream: boolean;
15
+ }
16
+
17
+ /** 插件模块导出的工厂接口 */
18
+ export interface PluginDefinition {
19
+ name: string;
20
+ version?: string;
21
+ create(params: Record<string, unknown>): Plugin | Promise<Plugin>;
22
+ }
23
+
24
+ /** 日志中记录的插件阶段信息 */
25
+ export interface PluginPhaseLog {
26
+ name: string;
27
+ package: string;
28
+ params: Record<string, unknown>;
29
+ }
30
+
31
+ /** 插件实例接口(三个核心处理器 + 错误处理 + 销毁) */
32
+ export interface Plugin {
33
+ onRequest?(args: {
34
+ ctx: PluginContext;
35
+ url: string;
36
+ headers: Headers;
37
+ body: Record<string, unknown>;
38
+ }): Promise<{ url?: string; headers?: Headers; body?: Record<string, unknown> } | void>;
39
+
40
+ onResponse?(args: {
41
+ ctx: PluginContext;
42
+ status: number;
43
+ headers: Record<string, string>;
44
+ body: string;
45
+ }): Promise<{ status?: number; headers?: Record<string, string>; body?: string } | void>;
46
+
47
+ onSSEResponse?(args: {
48
+ ctx: PluginContext;
49
+ status: number;
50
+ headers: Record<string, string>;
51
+ }): Promise<{
52
+ status?: number;
53
+ headers?: Record<string, string>;
54
+ transform?: TransformStream<Uint8Array, Uint8Array>;
55
+ } | void>;
56
+
57
+ onError?(args: {
58
+ ctx: PluginContext;
59
+ phase: 'request' | 'response';
60
+ error: Error;
61
+ }): Promise<void>;
62
+
63
+ dispose?(): void | Promise<void>;
64
+ }