@aipanel/core 1.2.7 → 1.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.
package/es/constants.d.ts CHANGED
@@ -37,8 +37,10 @@ export declare const START_API_PATH = "/__aipanel_start__";
37
37
  export declare const SESSIONS_API_PATH = "/__aipanel_sessions__";
38
38
  /** MCP 代理 API 路径 */
39
39
  export declare const MCP_API_PATH = "/__aipanel_mcp__";
40
- /** SSE 事件流路径 */
40
+ /** SSE 事件流路径(客户端订阅 SESSION_EVENT 等) */
41
41
  export declare const SSE_EVENTS_PATH = "/__aipanel_events__";
42
+ /** 宿主侧事件推送 API 路径(dsh-plugin 等 Host 插件把归一化 ProviderEvent POST 到这里,core 再广播给 SSE 客户端) */
43
+ export declare const HOST_EVENTS_API_PATH = "/__aipanel_host_events__";
42
44
  /** 上下文更新间隔(毫秒) */
43
45
  export declare const CONTEXT_UPDATE_INTERVAL = 500;
44
46
  /** 服务器同步间隔(毫秒) */
package/es/constants.mjs CHANGED
@@ -14,6 +14,7 @@ const START_API_PATH = "/__aipanel_start__";
14
14
  const SESSIONS_API_PATH = "/__aipanel_sessions__";
15
15
  const MCP_API_PATH = "/__aipanel_mcp__";
16
16
  const SSE_EVENTS_PATH = "/__aipanel_events__";
17
+ const HOST_EVENTS_API_PATH = "/__aipanel_host_events__";
17
18
  const CONTEXT_UPDATE_INTERVAL = 500;
18
19
  const SERVER_SYNC_INTERVAL = 2e3;
19
20
  const INSPECTOR_CHECK_INTERVAL = 500;
@@ -97,6 +98,7 @@ export {
97
98
  ENV_VSCODE_PORT,
98
99
  EXT_BROADCAST,
99
100
  EXT_MSG,
101
+ HOST_EVENTS_API_PATH,
100
102
  INIT_MARKER,
101
103
  INSPECTOR_CHECK_INTERVAL,
102
104
  LOGS_API_PATH,
@@ -28,7 +28,10 @@ export declare class RequestContext {
28
28
  path: string;
29
29
  startTime: number;
30
30
  private checkpoints;
31
- constructor(method: string, path: string);
31
+ private quiet;
32
+ constructor(method: string, path: string, options?: {
33
+ quiet?: boolean;
34
+ });
32
35
  checkpoint(label: string): void;
33
36
  end(statusCode: number): void;
34
37
  error(error: Error | unknown): void;
@@ -168,25 +168,32 @@ class PerformanceTimer {
168
168
  }
169
169
  }
170
170
  class RequestContext {
171
- constructor(method, path) {
171
+ constructor(method, path, options) {
172
172
  __publicField(this, "traceId");
173
173
  __publicField(this, "method");
174
174
  __publicField(this, "path");
175
175
  __publicField(this, "startTime");
176
176
  __publicField(this, "checkpoints", []);
177
+ __publicField(this, "quiet");
177
178
  this.traceId = _generateTraceId();
178
179
  this.method = method;
179
180
  this.path = path;
181
+ this.quiet = options?.quiet ?? false;
180
182
  this.startTime = performance.now();
181
- nodeLogger.debug(`\u2192 ${method} ${path}`, { traceId: this.traceId, module: "HTTP" });
183
+ if (!this.quiet) {
184
+ nodeLogger.debug(`\u2192 ${method} ${path}`, { traceId: this.traceId, module: "HTTP" });
185
+ }
182
186
  }
183
187
  checkpoint(label) {
184
188
  const elapsed = Math.round(performance.now() - this.startTime);
185
189
  this.checkpoints.push({ time: elapsed, label });
186
- nodeLogger.debug(` \u2192 ${label}`, { traceId: this.traceId, duration: elapsed });
190
+ if (!this.quiet) {
191
+ nodeLogger.debug(` \u2192 ${label}`, { traceId: this.traceId, duration: elapsed });
192
+ }
187
193
  }
188
194
  end(statusCode) {
189
195
  const duration = Math.round(performance.now() - this.startTime);
196
+ if (this.quiet) return;
190
197
  const statusColor = statusCode < 400 ? COLORS.green : COLORS.red;
191
198
  nodeLogger.debug(`\u2190 ${this.method} ${this.path} ${statusColor}${statusCode}${COLORS.reset}`, {
192
199
  traceId: this.traceId,
package/es/provider.d.ts CHANGED
@@ -74,6 +74,12 @@ export interface ProviderStartOptions {
74
74
  logsApiUrl?: string;
75
75
  /** Vue DevTools API 地址(核心层提供的回连地址) */
76
76
  vueDevtoolsApiUrl?: string;
77
+ /**
78
+ * 宿主事件推送令牌(核心层每轮启动随机生成,透传给 Host 侧插件)。
79
+ * dsh-plugin 监听宿主事件(session/event 总线)时须携带该令牌 POST 到 HOST_EVENTS_API_PATH,
80
+ * core 校验通过后按 SESSION_EVENT 广播给 SSE 客户端。无该能力/无需求的 Provider 忽略即可。
81
+ */
82
+ eventsToken?: string;
77
83
  /** 启用 verbose 模式 */
78
84
  verbose?: boolean;
79
85
  }
@@ -99,6 +105,12 @@ export interface ProviderStartResult {
99
105
  url: string;
100
106
  /** 进程句柄(供编排层做就绪等待与退出检测,不透明) */
101
107
  processHandle?: unknown;
108
+ /**
109
+ * 对 Provider Web 服务做浏览器会话认证所需的 Cookie(可选)。
110
+ * dsh web 升级后在索引页与 /api 上强制 browser-session 认证(launch token → 签名 cookie),
111
+ * 代理需在转发请求时注入该 Cookie 才能通过 401 门禁。opencode 等无需认证的 Provider 不设置。
112
+ */
113
+ webAuthCookie?: string;
102
114
  }
103
115
  /** Provider 初始化配置(主题/语言/设置等,schema 由 Provider 定义) */
104
116
  export interface ProviderConfig {
@@ -142,8 +154,12 @@ export interface WebProvider {
142
154
  stop(): Promise<void>;
143
155
  /** 清理孤儿进程(上次退出残留的 provider 进程),返回清理数量(可选) */
144
156
  killOrphans?(): Promise<number>;
145
- /** 会话管理(归一化到 ChatSession,过滤逻辑在此内部完成) */
146
- listSessions(projectDir: string): Promise<ChatSession[]>;
157
+ /**
158
+ * 会话管理(归一化到 ChatSession,过滤逻辑在此内部完成)。
159
+ * @param activeSessionId 当前选中会话 id(可选):用于对齐 dsh 等 UI 的可见性规则
160
+ * (blank 会话仅当其为当前选中会话时展示)。无选中态概念的 Provider 忽略即可。
161
+ */
162
+ listSessions(projectDir: string, activeSessionId?: string): Promise<ChatSession[]>;
147
163
  createSession(projectDir: string, title?: string): Promise<ChatSession>;
148
164
  /** 可选:部分 Provider 无删除语义;core 不支持时隐藏删除入口 */
149
165
  deleteSession?(sessionId: string): Promise<void>;
package/lib/constants.cjs CHANGED
@@ -34,6 +34,7 @@ __export(constants_exports, {
34
34
  ENV_VSCODE_PORT: () => ENV_VSCODE_PORT,
35
35
  EXT_BROADCAST: () => EXT_BROADCAST,
36
36
  EXT_MSG: () => EXT_MSG,
37
+ HOST_EVENTS_API_PATH: () => HOST_EVENTS_API_PATH,
37
38
  INIT_MARKER: () => INIT_MARKER,
38
39
  INSPECTOR_CHECK_INTERVAL: () => INSPECTOR_CHECK_INTERVAL,
39
40
  LOGS_API_PATH: () => LOGS_API_PATH,
@@ -78,6 +79,7 @@ const START_API_PATH = "/__aipanel_start__";
78
79
  const SESSIONS_API_PATH = "/__aipanel_sessions__";
79
80
  const MCP_API_PATH = "/__aipanel_mcp__";
80
81
  const SSE_EVENTS_PATH = "/__aipanel_events__";
82
+ const HOST_EVENTS_API_PATH = "/__aipanel_host_events__";
81
83
  const CONTEXT_UPDATE_INTERVAL = 500;
82
84
  const SERVER_SYNC_INTERVAL = 2e3;
83
85
  const INSPECTOR_CHECK_INTERVAL = 500;
@@ -162,6 +164,7 @@ const VUE_DEVTOOLS_ACTIONS = {
162
164
  ENV_VSCODE_PORT,
163
165
  EXT_BROADCAST,
164
166
  EXT_MSG,
167
+ HOST_EVENTS_API_PATH,
165
168
  INIT_MARKER,
166
169
  INSPECTOR_CHECK_INTERVAL,
167
170
  LOGS_API_PATH,
@@ -37,8 +37,10 @@ export declare const START_API_PATH = "/__aipanel_start__";
37
37
  export declare const SESSIONS_API_PATH = "/__aipanel_sessions__";
38
38
  /** MCP 代理 API 路径 */
39
39
  export declare const MCP_API_PATH = "/__aipanel_mcp__";
40
- /** SSE 事件流路径 */
40
+ /** SSE 事件流路径(客户端订阅 SESSION_EVENT 等) */
41
41
  export declare const SSE_EVENTS_PATH = "/__aipanel_events__";
42
+ /** 宿主侧事件推送 API 路径(dsh-plugin 等 Host 插件把归一化 ProviderEvent POST 到这里,core 再广播给 SSE 客户端) */
43
+ export declare const HOST_EVENTS_API_PATH = "/__aipanel_host_events__";
42
44
  /** 上下文更新间隔(毫秒) */
43
45
  export declare const CONTEXT_UPDATE_INTERVAL = 500;
44
46
  /** 服务器同步间隔(毫秒) */
@@ -189,25 +189,32 @@ class PerformanceTimer {
189
189
  }
190
190
  }
191
191
  class RequestContext {
192
- constructor(method, path) {
192
+ constructor(method, path, options) {
193
193
  __publicField(this, "traceId");
194
194
  __publicField(this, "method");
195
195
  __publicField(this, "path");
196
196
  __publicField(this, "startTime");
197
197
  __publicField(this, "checkpoints", []);
198
+ __publicField(this, "quiet");
198
199
  this.traceId = (0, import_logger_core.generateTraceId)();
199
200
  this.method = method;
200
201
  this.path = path;
202
+ this.quiet = options?.quiet ?? false;
201
203
  this.startTime = performance.now();
202
- nodeLogger.debug(`\u2192 ${method} ${path}`, { traceId: this.traceId, module: "HTTP" });
204
+ if (!this.quiet) {
205
+ nodeLogger.debug(`\u2192 ${method} ${path}`, { traceId: this.traceId, module: "HTTP" });
206
+ }
203
207
  }
204
208
  checkpoint(label) {
205
209
  const elapsed = Math.round(performance.now() - this.startTime);
206
210
  this.checkpoints.push({ time: elapsed, label });
207
- nodeLogger.debug(` \u2192 ${label}`, { traceId: this.traceId, duration: elapsed });
211
+ if (!this.quiet) {
212
+ nodeLogger.debug(` \u2192 ${label}`, { traceId: this.traceId, duration: elapsed });
213
+ }
208
214
  }
209
215
  end(statusCode) {
210
216
  const duration = Math.round(performance.now() - this.startTime);
217
+ if (this.quiet) return;
211
218
  const statusColor = statusCode < 400 ? COLORS.green : COLORS.red;
212
219
  nodeLogger.debug(`\u2190 ${this.method} ${this.path} ${statusColor}${statusCode}${COLORS.reset}`, {
213
220
  traceId: this.traceId,
@@ -28,7 +28,10 @@ export declare class RequestContext {
28
28
  path: string;
29
29
  startTime: number;
30
30
  private checkpoints;
31
- constructor(method: string, path: string);
31
+ private quiet;
32
+ constructor(method: string, path: string, options?: {
33
+ quiet?: boolean;
34
+ });
32
35
  checkpoint(label: string): void;
33
36
  end(statusCode: number): void;
34
37
  error(error: Error | unknown): void;
package/lib/provider.d.ts CHANGED
@@ -74,6 +74,12 @@ export interface ProviderStartOptions {
74
74
  logsApiUrl?: string;
75
75
  /** Vue DevTools API 地址(核心层提供的回连地址) */
76
76
  vueDevtoolsApiUrl?: string;
77
+ /**
78
+ * 宿主事件推送令牌(核心层每轮启动随机生成,透传给 Host 侧插件)。
79
+ * dsh-plugin 监听宿主事件(session/event 总线)时须携带该令牌 POST 到 HOST_EVENTS_API_PATH,
80
+ * core 校验通过后按 SESSION_EVENT 广播给 SSE 客户端。无该能力/无需求的 Provider 忽略即可。
81
+ */
82
+ eventsToken?: string;
77
83
  /** 启用 verbose 模式 */
78
84
  verbose?: boolean;
79
85
  }
@@ -99,6 +105,12 @@ export interface ProviderStartResult {
99
105
  url: string;
100
106
  /** 进程句柄(供编排层做就绪等待与退出检测,不透明) */
101
107
  processHandle?: unknown;
108
+ /**
109
+ * 对 Provider Web 服务做浏览器会话认证所需的 Cookie(可选)。
110
+ * dsh web 升级后在索引页与 /api 上强制 browser-session 认证(launch token → 签名 cookie),
111
+ * 代理需在转发请求时注入该 Cookie 才能通过 401 门禁。opencode 等无需认证的 Provider 不设置。
112
+ */
113
+ webAuthCookie?: string;
102
114
  }
103
115
  /** Provider 初始化配置(主题/语言/设置等,schema 由 Provider 定义) */
104
116
  export interface ProviderConfig {
@@ -142,8 +154,12 @@ export interface WebProvider {
142
154
  stop(): Promise<void>;
143
155
  /** 清理孤儿进程(上次退出残留的 provider 进程),返回清理数量(可选) */
144
156
  killOrphans?(): Promise<number>;
145
- /** 会话管理(归一化到 ChatSession,过滤逻辑在此内部完成) */
146
- listSessions(projectDir: string): Promise<ChatSession[]>;
157
+ /**
158
+ * 会话管理(归一化到 ChatSession,过滤逻辑在此内部完成)。
159
+ * @param activeSessionId 当前选中会话 id(可选):用于对齐 dsh 等 UI 的可见性规则
160
+ * (blank 会话仅当其为当前选中会话时展示)。无选中态概念的 Provider 忽略即可。
161
+ */
162
+ listSessions(projectDir: string, activeSessionId?: string): Promise<ChatSession[]>;
147
163
  createSession(projectDir: string, title?: string): Promise<ChatSession>;
148
164
  /** 可选:部分 Provider 无删除语义;core 不支持时隐藏删除入口 */
149
165
  deleteSession?(sessionId: string): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aipanel/core",
3
- "version": "1.2.7",
3
+ "version": "1.2.8",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "main": "lib/index.cjs",