@faapi/faapi 6.23.0 → 6.25.0

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.
@@ -60,13 +60,13 @@ interface ToolPathMeta {
60
60
  /**
61
61
  * Agent 的 LLM 可见核心字段
62
62
  *
63
- * 描述"agent 是什么"——LLM 真正需要消费的字段,**不含**代码本体加载细节
64
- * (filePath / hasRun)。文件型 agent 与 DB-driven skill 都实现此接口。
63
+ * 描述"agent 是什么"——LLM 真正需要消费的字段,**不含**声明文件定位信息
64
+ * (filePath)。文件型 agent 与 DB-driven skill 都实现此接口。
65
65
  *
66
66
  * - 文件型 agent:由 [AgentMetadata](./extractAgentMetadata.md) 继承扩展,
67
- * 额外含 `filePath` / `hasRun`(代码本体加载用)
67
+ * 额外含 `filePath`(声明文件定位用)
68
68
  * - DB-driven skill:业务方 plugin 从 DB 字段映射到本接口即可,无需填占位值
69
- * (skill 无源文件,不走 `loadAgentModule`,自然不读 filePath / hasRun)
69
+ * (skill 无源文件,自然不读 filePath)
70
70
  *
71
71
  * `@faapi/agent` 子包的 `Agent` 类、`agentRegistry` 查询入口、`asTool` 包装
72
72
  * 都消费 `AgentCore`,实现"agent 与 skill 走同一运行时链路"。
@@ -78,6 +78,16 @@ interface AgentCore {
78
78
  description?: string;
79
79
  /** 系统提示词(config 块字面量提取);文件型 agent 必填(构建期校验),DB skill 由业务方自治 */
80
80
  systemPrompt?: string;
81
+ /**
82
+ * 系统提示词文件路径(config 块字面量提取),相对产物 resources 目录
83
+ * (`<dist>/resources/`,即 `ctx.resourcesDir`),与 `systemPrompt` 互斥
84
+ * (都声明构建期抛错,二选一必填)
85
+ *
86
+ * 运行时每次 run 读文件内容作为 systemPrompt——dev 改 prompt 文件经 watcher
87
+ * 增量复制后立即生效,无需 reload;`deps.resourcesDir` 未注入或文件读取失败
88
+ * 时抛 `AgentError`(不静默降级)
89
+ */
90
+ systemPromptFile?: string;
81
91
  /** agent 显式声明可用的 tool 引用列表(config 块字面量提取),未声明时为 `undefined`;声明了但含无法静态求值的元素在构建期抛错 */
82
92
  tools?: string[];
83
93
  /** 可调用的其他 agent 名列表(config 块字面量提取),未声明时为 `undefined`;声明了但含无法静态求值的元素在构建期抛错 */
@@ -99,12 +109,13 @@ interface AgentCore {
99
109
  /**
100
110
  * Agent 完整元数据(文件型 agent)
101
111
  *
102
- * 继承 [AgentCore](./extractAgentMetadata.md) 的 LLM 字段,额外扩展**代码本体加载细节**:
103
- * - `filePath` — `loadAgentModule` 加载 `handler.js` 产物提取 `run` 函数用
104
- * - `hasRun` — 是否导出 `run` 函数(`Agent.executeSubAgent` 据此决定走自定义 run
105
- * 还是默认 reactLoop)
112
+ * 继承 [AgentCore](./extractAgentMetadata.md) 的 LLM 字段,额外扩展声明文件定位:
113
+ * - `filePath` — 声明文件源码相对路径(启动日志 / 清单可观测性用)
106
114
  *
107
- * DB-driven skill 不实现此接口(无源文件,无需加载),只实现 `AgentCore`。
115
+ * agent 统一为声明式执行(config + 默认 reactLoop)——自定义 `run` 导出已移除,
116
+ * 检测到 run 导出在提取阶段抛迁移错误(编排场景注册 tool)。
117
+ *
118
+ * DB-driven skill 不实现此接口(无源文件),只实现 `AgentCore`。
108
119
  *
109
120
  * 由 [extractAgentMetadata](./extractAgentMetadata.md) 产出,合并路径推导字段
110
121
  * (来自 [scanAgents](../agents/scanAgents.md) 的 `AgentManifest`)与 AST 提取字段
@@ -112,15 +123,13 @@ interface AgentCore {
112
123
  *
113
124
  * 字段来源:
114
125
  * - `name` — `@agent` JSDoc 覆盖值,或 `pathMeta.name`(目录推导)
115
- * - `filePath` / `hasRun` — 由 `pathMeta` 透传
126
+ * - `filePath` — 由 `pathMeta` 透传
116
127
  * - `description` — JSDoc 注释块自由文本(对 LLM 可见)
117
- * - `systemPrompt` / `tools` / `agents` / `model` / `maxTurns` / `inputDescription` — config 块字面量提取
128
+ * - `systemPrompt` / `systemPromptFile` / `tools` / `agents` / `model` / `maxTurns` / `inputDescription` — config 块字面量提取
118
129
  */
119
130
  interface AgentMetadata extends AgentCore {
120
- /** 源码相对路径(从 `pathMeta` 透传),`loadAgentModule` 据此加载 `handler.js` 提取 `run` */
131
+ /** 源码相对路径(从 `pathMeta` 透传)——声明文件定位与清单可观测性用 */
121
132
  filePath: string;
122
- /** 是否导出 `run` 函数(从 `pathMeta` 透传),`Agent.executeSubAgent` 据此选择自定义 run / 默认 reactLoop */
123
- hasRun: boolean;
124
133
  }
125
134
  /**
126
135
  * 路径推导的 agent 元数据(由 [scanAgents](../agents/scanAgents.ts) 计算)
@@ -133,8 +142,6 @@ interface AgentPathMeta {
133
142
  name: string;
134
143
  /** 源码相对路径(如 `src/agents/researcher/handler.ts`) */
135
144
  filePath: string;
136
- /** 是否导出 `run` 函数(scanAgents 正则检测) */
137
- hasRun: boolean;
138
145
  }
139
146
 
140
147
  /**
@@ -356,6 +363,12 @@ interface TaskWorkerOptions {
356
363
  /** signal 由执行器构造(abort/terminate 时触发),宿主只传 config 与 job 信息 */
357
364
  taskCtx: {
358
365
  config: unknown;
366
+ /**
367
+ * 产物 resources 目录绝对路径(纯字符串可结构化克隆)——两处用途:经
368
+ * workerData 传给入口在任务模块求值前播种全局读取根 + 挂到 worker 内的
369
+ * taskCtx(业务方了解/拼接资源位置)
370
+ */
371
+ resourcesDir?: string;
359
372
  job: {
360
373
  id: string;
361
374
  name: string;
@@ -439,7 +452,7 @@ interface AgentRegistry {
439
452
  hydrate(agents: AgentMetadata[]): void;
440
453
  /** LLM 可见元数据(AgentCore) */
441
454
  getAgent(name: string): AgentCore | undefined;
442
- /** 完整元数据(含 filePath / hasRun,供加载 handler.js 执行 run) */
455
+ /** 完整元数据(含 filePath,声明文件定位) */
443
456
  getAgentEntry(name: string): AgentMetadata | undefined;
444
457
  /** 所有已注册 agent 的 LLM 可见元数据(副本) */
445
458
  listAgents(): AgentCore[];
@@ -602,7 +615,7 @@ interface TaskJob {
602
615
  * `TaskRegistriesView` 生成快照,worker wrapper 内重建只读视图。
603
616
  */
604
617
  interface TaskRegistriesSnapshot {
605
- /** agent 完整元数据(含 filePath/hasRun,非仅 LLM 可见字段) */
618
+ /** agent 完整元数据(含 filePath,非仅 LLM 可见字段) */
606
619
  agents: AgentMetadata[];
607
620
  tools: ToolMetadata[];
608
621
  skills: AgentCore[];
@@ -615,6 +628,14 @@ interface TaskContext {
615
628
  signal: AbortSignal;
616
629
  /** faapi.config.ts 全量配置(含自定义业务配置) */
617
630
  config: unknown;
631
+ /**
632
+ * 产物 resources 目录绝对路径(`<rootDir>/<dist>/resources`)
633
+ *
634
+ * 任务读静态文件(prompt 模板等)用:`fs.readFile(path.join(taskCtx.resourcesDir, 'x.md'))`。
635
+ * 进程内与隔离执行两条路径均注入(隔离为纯字符串,可结构化克隆);
636
+ * 直接构造 TaskContext 的测试/自定义执行器可不传。
637
+ */
638
+ resourcesDir?: string;
618
639
  job: {
619
640
  id: string;
620
641
  name: string;
@@ -625,7 +646,7 @@ interface TaskContext {
625
646
  *
626
647
  * 进程内执行为活引用;隔离执行为派发时刻的快照视图(worker 内重建)——
627
648
  * 执行中途的 reload/DB skill 变更不影响当次执行。
628
- * 任务内组装 agent 用 `registries.agent.getAgentEntry(name)`(含 filePath/hasRun)。
649
+ * 任务内组装 agent 用 `registries.agent.getAgentEntry(name)`(含 filePath)。
629
650
  */
630
651
  registries: TaskRegistriesView;
631
652
  /**
@@ -714,6 +735,11 @@ interface TaskQueueDeps {
714
735
  rootDir: string;
715
736
  /** faapi.config.ts 全量配置,透传给 run 的 TaskContext.config */
716
737
  config?: unknown;
738
+ /**
739
+ * 产物 resources 目录绝对路径——注入两条执行路径的 TaskContext.resourcesDir;
740
+ * 缺省不注入(直接构造队列的测试/嵌入场景)
741
+ */
742
+ resourcesDir?: string;
717
743
  /**
718
744
  * app 注册表只读视图(`createTaskRegistriesView`)——注入两条执行路径的
719
745
  * TaskContext.registries;缺省为空视图(直接构造队列的测试/嵌入场景)
@@ -1028,8 +1054,9 @@ interface FaapiContext {
1028
1054
  /**
1029
1055
  * 运行时资源根目录绝对路径(<rootDir>/<dist>/resources)
1030
1056
  *
1031
- * `src/resources/` 经 dev/build 复制进产物后的位置,handler 读静态文件用:
1032
- * `await fs.readFile(path.join(ctx.resourcesDir, 'prompts/foo.md'))`。
1057
+ * `src/resources/` 经 dev/build 复制进产物后的位置。数据字段——读取统一走
1058
+ * 免传参的 `readResource('prompts/foo.md')`(app 启动时绑定,见
1059
+ * src/utils/readResource.md),本字段供业务方了解/拼接资源位置。
1033
1060
  * HTTP/WS 请求链路恒有值;testing 直调(createTestContext)未传时为 undefined。
1034
1061
  */
1035
1062
  resourcesDir?: string;
@@ -1148,205 +1175,4 @@ interface FaapiContext {
1148
1175
  deleteCookie(name: string): void;
1149
1176
  }
1150
1177
 
1151
- /**
1152
- * faapi 中间件(洋葱模型)
1153
- *
1154
- * 单一 async 函数,通过 `await next()` 衔接前置/后置逻辑:
1155
- * - `await next()` 之前的代码:前置处理(鉴权、日志开始计时等)
1156
- * - `await next()` 之后的代码:后置处理(日志输出、响应修改等)
1157
- * - 不调用 `next()` 即拦截请求(如鉴权失败直接返回 Response)
1158
- * - `next()` 返回内层 Response,中间件可选择使用或替换
1159
- * - 返回 `Response`:作为响应返回(可用于拦截或错误处理)
1160
- * - 返回 `void`:使用 `await next()` 返回的内层响应
1161
- *
1162
- * 错误处理用 try/catch 包裹 `await next()`,而非独立的 error 钩子。
1163
- *
1164
- * 执行顺序(洋葱模型):
1165
- * ```
1166
- * mw1.before → mw2.before → handler → mw2.after → mw1.after
1167
- * ```
1168
- *
1169
- * 示例 middlewares.ts:
1170
- * ```ts
1171
- * import type { FaapiMiddleware } from '@faapi/faapi';
1172
- *
1173
- * export default [
1174
- * // 鉴权:不调 next() 即拦截
1175
- * async (ctx, next) => {
1176
- * const token = ctx.headers.get('authorization');
1177
- * if (!token) return new Response('Unauthorized', { status: 401 });
1178
- * ctx.user = await verifyToken(token);
1179
- * await next();
1180
- * },
1181
- * // 日志:before/after 一体,闭包共享状态
1182
- * async (ctx, next) => {
1183
- * const start = Date.now();
1184
- * await next();
1185
- * console.log(`${ctx.method} ${ctx.path} ${Date.now() - start}ms`);
1186
- * },
1187
- * // 错误处理:try/catch 语义
1188
- * async (ctx, next) => {
1189
- * try {
1190
- * await next();
1191
- * } catch (err) {
1192
- * return new Response(JSON.stringify({ error: String(err) }), { status: 500 });
1193
- * }
1194
- * },
1195
- * ] satisfies FaapiMiddleware[];
1196
- * ```
1197
- */
1198
- type FaapiMiddleware = (ctx: FaapiContext, next: () => Promise<Response>) => Promise<void | Response>;
1199
-
1200
- /**
1201
- * 注入器:按参数名匹配,提供 handler 所需的依赖
1202
- *
1203
- * 注入器是 faapi 的依赖注入扩展点,与中间件解耦:
1204
- * - 中间件只管请求流程(鉴权、日志、错误处理)
1205
- * - 注入器只管提供依赖(数据库连接、用户对象等)
1206
- *
1207
- * 注入器可以读取中间件塞进 ctx 的值(如鉴权中间件塞的 ctx.user),
1208
- * 也可以独立提供依赖(如数据库连接池)。
1209
- *
1210
- * 注入器按需执行:只对 handler 声明的参数执行对应的注入器,避免无谓计算。
1211
- *
1212
- * 在 middlewares.ts 中通过命名导出 `injectors` 注册:
1213
- * ```ts
1214
- * import type { InjectorMap } from '@faapi/faapi';
1215
- *
1216
- * export const injectors: InjectorMap = {
1217
- * db: () => getDbConnection(),
1218
- * user: (ctx) => ctx.user, // 取中间件塞的值
1219
- * };
1220
- * ```
1221
- */
1222
- type Injector = (ctx: FaapiContext) => unknown | Promise<unknown>;
1223
- /**
1224
- * 注入器映射表:参数名 → 注入器函数
1225
- *
1226
- * key 必须与 handler 参数名一致,运行时按参数名匹配执行。
1227
- */
1228
- type InjectorMap = Record<string, Injector>;
1229
-
1230
- interface CorsOptions {
1231
- origin?: string | string[] | true;
1232
- methods?: string[];
1233
- allowedHeaders?: string[];
1234
- exposeHeaders?: string[];
1235
- credentials?: boolean;
1236
- maxAge?: number;
1237
- }
1238
- /**
1239
- * 创建 CORS 中间件(洋葱模型)
1240
- *
1241
- * - origin=true: 允许所有来源(反射请求的 Origin)
1242
- * - origin=string: 允许指定来源
1243
- * - origin=string[]: 允许多个来源
1244
- *
1245
- * OPTIONS 预检请求直接返回 204,不调用 next()。
1246
- */
1247
- declare function cors(options?: CorsOptions): FaapiMiddleware;
1248
-
1249
- interface HelmetOptions {
1250
- contentSecurityPolicy?: string | false;
1251
- xFrameOptions?: 'DENY' | 'SAMEORIGIN' | false;
1252
- xContentTypeOptions?: boolean;
1253
- referrerPolicy?: string | false;
1254
- strictTransportSecurity?: string | false;
1255
- xDnsPrefetchControl?: boolean;
1256
- xDownloadOptions?: boolean;
1257
- xPermittedCrossDomainPolicies?: string | false;
1258
- crossOriginOpenerPolicy?: string | false;
1259
- crossOriginResourcePolicy?: string | false;
1260
- crossOriginEmbedderPolicy?: string | false;
1261
- originAgentCluster?: boolean;
1262
- xPoweredBy?: boolean;
1263
- }
1264
- declare function helmet(options?: HelmetOptions): FaapiMiddleware;
1265
-
1266
- declare const HTTP_METHODS: readonly ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD", "OPTIONS"];
1267
- type HttpMethod = (typeof HTTP_METHODS)[number];
1268
-
1269
- interface RouteRecord {
1270
- method: HttpMethod;
1271
- urlPath: string;
1272
- filePath: string;
1273
- paramNames: string[];
1274
- isDynamic: boolean;
1275
- /** 是否为 catch-all 路由([...slug]) */
1276
- isCatchAll?: boolean;
1277
- /** 中间件文件绝对路径列表(根在前,路由目录在后;按需加载用) */
1278
- middlewarePaths?: string[];
1279
- /** 路由对应的中间件集合(从根到路由目录合并,按需加载后缓存) */
1280
- middlewares?: FaapiMiddleware[];
1281
- /** 路由对应的注入器映射表(从根到路由目录合并,按需加载后缓存) */
1282
- injectors?: InjectorMap;
1283
- }
1284
- /**
1285
- * WebSocket 路由记录
1286
- *
1287
- * 与 HTTP RouteRecord 类似,但不绑定 HTTP 方法(WS 是协议升级,不区分 GET/POST)。
1288
- * 一个 handler.ts 中导出 WS 即生成一条 WS 路由记录。
1289
- */
1290
- interface WsRouteRecord {
1291
- urlPath: string;
1292
- filePath: string;
1293
- paramNames: string[];
1294
- isDynamic: boolean;
1295
- /** 是否为 catch-all 路由([...slug]) */
1296
- isCatchAll?: boolean;
1297
- /** 中间件文件绝对路径列表(根在前,路由目录在后;按需加载用) */
1298
- middlewarePaths?: string[];
1299
- /** 路由对应的中间件集合(握手阶段执行,复用鉴权/CORS/日志;按需加载后缓存) */
1300
- middlewares?: FaapiMiddleware[];
1301
- /** 路由对应的注入器映射表 */
1302
- injectors?: InjectorMap;
1303
- }
1304
- type RouteManifest = RouteRecord[];
1305
- type WsRouteManifest = WsRouteRecord[];
1306
- /**
1307
- * 路由单个参数的 schema 描述
1308
- *
1309
- * 供 @faapi/schema 扩展包消费,通过 MCP 暴露给 LLM。
1310
- */
1311
- interface RouteParamSchema {
1312
- name: string;
1313
- type: string;
1314
- required: boolean;
1315
- }
1316
- /**
1317
- * 路由单个输入源的 schema 描述
1318
- */
1319
- interface RouteInputSchema {
1320
- source: 'query' | 'body' | 'params';
1321
- schemaName: string | null;
1322
- properties: RouteParamSchema[];
1323
- }
1324
- /**
1325
- * 路由响应类型的 schema 描述
1326
- *
1327
- * 由 @faapi/schema 扩展包的 buildRouteSchemas 生成。
1328
- * output 为 null 表示无显式返回类型注解、void/Promise<void>、或解析失败降级。
1329
- */
1330
- interface RouteOutputSchema {
1331
- /** 命名类型名(如 'UserResponse'),内联类型为 null */
1332
- schemaName: string | null;
1333
- /** 顶层属性列表 */
1334
- properties: RouteParamSchema[];
1335
- }
1336
- /**
1337
- * 路由的完整 schema 描述
1338
- *
1339
- * 由 @faapi/schema 扩展包的 buildRouteSchemas 生成。
1340
- * 主包只定义类型契约,逻辑实现在扩展包。
1341
- */
1342
- interface RouteInfo {
1343
- method: string;
1344
- path: string;
1345
- filePath: string;
1346
- isDynamic: boolean;
1347
- inputs: RouteInputSchema[];
1348
- /** 响应类型描述(null 表示无返回类型注解/void/解析失败) */
1349
- output: RouteOutputSchema | null;
1350
- }
1351
-
1352
- export { type ToolPathMeta as $, type AppRegistries as A, type RouteOutputSchema as B, type CorsOptions as C, type RouteParamSchema as D, type SseEvent as E, type FaapiMiddleware as F, type SseOptions as G, type HelmetOptions as H, type InjectorMap as I, type SseWriter as J, type TaskContext as K, type LogConfig as L, type TaskDriverJob as M, type TaskDriverProcess as N, type TaskDriverRecord as O, type TaskFailedInfo as P, type TaskJob as Q, type RouteManifest as R, type SkillRegistry as S, type TaskClient as T, type TaskJobStatus as U, type TaskMetadata as V, type WsRouteManifest as W, type TaskModule as X, type TaskRegistriesSnapshot as Y, type TaskRegistriesView as Z, type ToolCore as _, type FaapiContext as a, type ToolRegistry as a0, cors as a1, createAppRegistries as a2, createTaskRegistriesView as a3, createTaskRegistry as a4, helmet as a5, type TaskFailedHandler as b, type TaskQueueDeps as c, type TaskQueue as d, type TaskDriver as e, type TaskRegistry as f, type TaskManifest as g, type ToolMetadata as h, type AgentCore as i, type AgentMetadata as j, type CreateLoggerOptions as k, type Logger as l, type AgentHandleFactory as m, type AgentHandleStore as n, type AgentPathMeta as o, type AgentRegistry as p, type AgentToolDescriptor as q, type FaapiContextConfig as r, type FaapiTaskMeta as s, type FailOptions as t, type Injector as u, type LogEntry as v, type LogLevel as w, type LogSink as x, type RouteInfo as y, type RouteInputSchema as z };
1178
+ export { type AppRegistries as A, type TaskDriverProcess as B, type CreateLoggerOptions as C, type TaskDriverRecord as D, type TaskFailedInfo as E, type FaapiContext as F, type TaskJob as G, type TaskJobStatus as H, type TaskMetadata as I, type TaskModule as J, type TaskRegistriesSnapshot as K, type LogConfig as L, type TaskRegistriesView as M, type ToolCore as N, type ToolPathMeta as O, type ToolRegistry as P, createAppRegistries as Q, createTaskRegistriesView as R, type SkillRegistry as S, type TaskClient as T, createTaskRegistry as U, type TaskFailedHandler as a, type TaskQueueDeps as b, type TaskQueue as c, type TaskDriver as d, type TaskRegistry as e, type TaskManifest as f, type ToolMetadata as g, type AgentCore as h, type AgentMetadata as i, type Logger as j, type AgentHandleFactory as k, type AgentHandleStore as l, type AgentPathMeta as m, type AgentRegistry as n, type AgentToolDescriptor as o, type FaapiContextConfig as p, type FaapiTaskMeta as q, type FailOptions as r, type LogEntry as s, type LogLevel as t, type LogSink as u, type SseEvent as v, type SseOptions as w, type SseWriter as x, type TaskContext as y, type TaskDriverJob as z };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
- import { F as FaapiMiddleware, A as AppRegistries, R as RouteManifest, a as FaapiContext, C as CorsOptions, T as TaskClient, H as HelmetOptions, L as LogConfig, I as InjectorMap, b as TaskFailedHandler, W as WsRouteManifest, c as TaskQueueDeps, d as TaskQueue, e as TaskDriver, f as TaskRegistry, g as TaskManifest, h as ToolMetadata, i as AgentCore, j as AgentMetadata, k as CreateLoggerOptions, l as Logger } from './routeTypes-CJV5M90s.js';
2
- export { m as AgentHandleFactory, n as AgentHandleStore, o as AgentPathMeta, p as AgentRegistry, q as AgentToolDescriptor, r as FaapiContextConfig, s as FaapiTaskMeta, t as FailOptions, u as Injector, v as LogEntry, w as LogLevel, x as LogSink, y as RouteInfo, z as RouteInputSchema, B as RouteOutputSchema, D as RouteParamSchema, S as SkillRegistry, E as SseEvent, G as SseOptions, J as SseWriter, K as TaskContext, M as TaskDriverJob, N as TaskDriverProcess, O as TaskDriverRecord, P as TaskFailedInfo, Q as TaskJob, U as TaskJobStatus, V as TaskMetadata, X as TaskModule, Y as TaskRegistriesSnapshot, Z as TaskRegistriesView, _ as ToolCore, $ as ToolPathMeta, a0 as ToolRegistry, a1 as cors, a2 as createAppRegistries, a3 as createTaskRegistriesView, a4 as createTaskRegistry, a5 as helmet } from './routeTypes-CJV5M90s.js';
1
+ import { A as AppRegistries, F as FaapiContext, T as TaskClient, L as LogConfig, a as TaskFailedHandler, b as TaskQueueDeps, c as TaskQueue, d as TaskDriver, e as TaskRegistry, f as TaskManifest, g as ToolMetadata, h as AgentCore, i as AgentMetadata, C as CreateLoggerOptions, j as Logger } from './contextTypes-gYf84EXF.js';
2
+ export { k as AgentHandleFactory, l as AgentHandleStore, m as AgentPathMeta, n as AgentRegistry, o as AgentToolDescriptor, p as FaapiContextConfig, q as FaapiTaskMeta, r as FailOptions, s as LogEntry, t as LogLevel, u as LogSink, S as SkillRegistry, v as SseEvent, w as SseOptions, x as SseWriter, y as TaskContext, z as TaskDriverJob, B as TaskDriverProcess, D as TaskDriverRecord, E as TaskFailedInfo, G as TaskJob, H as TaskJobStatus, I as TaskMetadata, J as TaskModule, K as TaskRegistriesSnapshot, M as TaskRegistriesView, N as ToolCore, O as ToolPathMeta, P as ToolRegistry, Q as createAppRegistries, R as createTaskRegistriesView, U as createTaskRegistry } from './contextTypes-gYf84EXF.js';
3
+ import { F as FaapiMiddleware, R as RouteManifest, C as CorsOptions, H as HelmetOptions, I as InjectorMap, W as WsRouteManifest } from './routeTypes-DlD6nnbT.js';
4
+ export { a as Injector, b as RouteInfo, c as RouteInputSchema, d as RouteOutputSchema, e as RouteParamSchema, f as cors, h as helmet } from './routeTypes-DlD6nnbT.js';
3
5
  import * as node_http from 'node:http';
4
6
  import { Server, IncomingMessage, ServerResponse } from 'node:http';
5
7
  import { Socket } from 'node:net';
@@ -48,6 +50,14 @@ type UpgradeHandler = (req: IncomingMessage, socket: Socket, head: Buffer) => vo
48
50
  interface PluginContext {
49
51
  /** 项目根目录 */
50
52
  rootDir: string;
53
+ /**
54
+ * 产物 resources 目录绝对路径(`<rootDir>/<dist>/resources`)
55
+ *
56
+ * `src/resources/` 经 dev/build 复制进产物后的位置——插件 setup 时读静态
57
+ * 资源用;`@faapi/agent` 插件据此注入 AgentDeps(agent config 的
58
+ * systemPromptFile 相对此目录解析)。
59
+ */
60
+ resourcesDir: string;
51
61
  /** app 级注册表(tool/agent/skill/agentHandle 实例,随 app 生命周期) */
52
62
  registries: AppRegistries;
53
63
  /** 当前路由清单(setup 时的快照,reloadRoutes 后不会更新;需最新路由用 getRoutes()) */
@@ -1258,52 +1268,6 @@ declare const TASK_PATTERNS: string[];
1258
1268
  */
1259
1269
  declare function scanTasks(rootDir: string, patterns: string[]): Promise<TaskManifest[]>;
1260
1270
 
1261
- /**
1262
- * 加载后的 agent 模块
1263
- *
1264
- * 与 [ToolModule](./loadToolModule.md) 对称——agent 的代码本体只有可选的 `run` 函数
1265
- * (自定义 agent 运行逻辑,替代默认 reactLoop)。
1266
- *
1267
- * > `config` 字段已移除——`AgentMetadata` 已含 AST 提取的字面量字段
1268
- * > (systemPrompt / tools / agents / model / maxTurns),`AgentModule.config`
1269
- * > 原本用于运行时拿到完整 config 对象(含动态字段),但 `executeSubAgent`
1270
- * > 拿到 `mod.config` 后从不读取(run 函数在自己模块内直接引用 config 变量),
1271
- * > 属于死链路,故移除。
1272
- *
1273
- * `AgentMetadata`(从 `faapi-agents.js` 水合)已含字面量字段,本模块仅用于
1274
- * 在运行时拿到 `run` 函数引用。
1275
- */
1276
- interface AgentModule {
1277
- /**
1278
- * 自定义 agent 运行函数(可选)
1279
- *
1280
- * `hasRun` 为 true 时一定为 function;为 false 时为 `undefined`。
1281
- * 调用方式由 `@faapi/agent` 子包的 Agent 类定义(Phase 3.x)。
1282
- */
1283
- run: ((...args: unknown[]) => unknown) | undefined;
1284
- }
1285
- /**
1286
- * 动态 import agent handler 文件并提取 `run` 导出
1287
- *
1288
- * Dev 按需编译模式(Vite 风格):先 `ensureCompiled` 确保产物存在再 import,
1289
- * 避免 import 不存在的文件污染 Vite SSR 内部状态(详见 [loadRouteModule](./loadRouteModule.md))。
1290
- * Prod 模式:产物在 build 阶段已固化,直接 import,失败即报错。
1291
- *
1292
- * 与 [loadToolModule](./loadToolModule.md) 的差异:
1293
- * - tool 按 `functionName` 提取单个函数(校验为 function)
1294
- * - agent 只提取 `run`(函数,可选)——config 块字段已在 AST 阶段提取为字面量,
1295
- * 运行时无需再加载 config 对象
1296
- *
1297
- * 错误传递:
1298
- * - 编译失败 → 抛 "Failed to compile agent module"
1299
- * - import 失败 → 抛 "Failed to load agent module"
1300
- *
1301
- * @param filePath agent handler 文件的绝对路径(产物形式,如 `dist/agents/researcher/handler.js`)
1302
- * @param hasRun 是否应提取 run 导出(来自 `AgentMetadata.hasRun`)
1303
- * @param rootDir 项目根目录(按需编译模式用,可选)
1304
- */
1305
- declare function loadAgentModule(filePath: string, hasRun: boolean, rootDir?: string): Promise<AgentModule>;
1306
-
1307
1271
  /**
1308
1272
  * 加载后的 tool 模块
1309
1273
  *
@@ -1382,14 +1346,14 @@ declare function loadToolSchema(tool: ToolMetadata, rootDir?: string): Promise<T
1382
1346
  /**
1383
1347
  * 按名查找单个 agent 的 LLM 可见元数据(默认实例)
1384
1348
  *
1385
- * 返回 [AgentCore](../ast/extractAgentMetadata.md)(不含 filePath / hasRun)。
1349
+ * 返回 [AgentCore](../ast/extractAgentMetadata.md)(不含 filePath)。
1386
1350
  * 加载 handler.js 执行 `run` 函数请用 [getAgentEntry](#getAgentEntry)。
1387
1351
  *
1388
1352
  * @param name agent 名(如 `researcher`,含 `@agent` 覆盖值)
1389
1353
  */
1390
1354
  declare function getAgent(name: string): AgentCore | undefined;
1391
1355
  /**
1392
- * 按名查找单个 agent 的完整元数据(默认实例,含 filePath / hasRun)
1356
+ * 按名查找单个 agent 的完整元数据(默认实例,含 filePath)
1393
1357
  */
1394
1358
  declare function getAgentEntry(name: string): AgentMetadata | undefined;
1395
1359
  /**
@@ -1527,6 +1491,17 @@ declare function loadConfig(rootDir: string, dist: string): Promise<Partial<Faap
1527
1491
  */
1528
1492
  declare function loadEnv(rootDir: string): void;
1529
1493
 
1494
+ /**
1495
+ * 读取当前 app 的运行时资源内容(参数为相对路径,只能读 resources 内的文件)
1496
+ *
1497
+ * 唯一读取入口:HTTP/WS handler、任务、插件、lifecycle 钩子、编程式调用全部用
1498
+ * 本函数——resources 目录在 app 启动时绑定(createAppBase),调用方不传路径根。
1499
+ * 越界校验见 resolveResourceTarget——绝对路径、`..` 穿越、符号链接逃逸均显式抛错,
1500
+ * resources 内部的合法软链不误伤。
1501
+ */
1502
+ declare function readResource(relativePath: string): Promise<Buffer>;
1503
+ declare function readResource(relativePath: string, encoding: BufferEncoding): Promise<string>;
1504
+
1530
1505
  /**
1531
1506
  * 设置全局日志配置(进程级,`createAppBase` 启动时以 `config.log` 调用)
1532
1507
  *
@@ -1790,4 +1765,4 @@ type ProdApp = AppBase;
1790
1765
  */
1791
1766
  declare function createProdApp(options?: CreateAppOptions): Promise<ProdApp>;
1792
1767
 
1793
- export { type AgentConfig, AgentCore, AgentMetadata, type AgentModule, type ProdApp as App, AppRegistries, CorsOptions, type CreateAppOptions, CreateLoggerOptions, type CronScheduler, type DevApp, type FaapiConfig, FaapiContext, FaapiError, FaapiMiddleware, type FaapiPlugin, type HandlerTypeInfo, HelmetOptions, type InjectOptions, type InjectResponse, InjectorMap, InternalError, type LifecycleContext, type LifecycleHooks, type LlmConfig, type LlmModelConfig, LogConfig, Logger, type LoggerOptions, MethodNotAllowedError, ModuleLoadError, type PluginContext, type PluginDeclaration, type ProdApp, type PropertyType, type RequestHandler, type ResponseConfig, RouteManifest, RouteNotFoundError, type RouteSchemaSource, type RuntimeType, SchemaExtractionError, TASK_PATTERNS, type TaskBullMqOptions, TaskClient, type TaskConfig, TaskDriver, TaskFailedHandler, TaskManifest, type TaskPgBossOptions, TaskQueue, TaskRegistry, ToolMetadata, type ToolModule, type ToolSchemaModule, type TypeConstraint, type UpgradeHandler, ValidationError, type ValidationErrorCode, type ValidationIssue, type WsContext, type WsEventHandlers, type WsHandler, type WsSocket, clearAgentHandleFactory, collectRouteSchemaSources, configureLogging, createProdApp as createApp, createCronScheduler, createDevApp, createLogger, createProdApp, createProgram, createPrograms, createTaskQueue, extractTypeInfo, flushLogging, getAgent, getAgentEntry, getApp, getInputTypeForMethod, getSkill, getTool, getToolSchemaPath, hydrateSkillRegistry, invalidateProgramCache, listSkills, loadAgentModule, loadConfig, loadEnv, loadTaskDriver, loadToolModule, loadToolSchema, logger, registerAgentHandleFactory, removeSkill, resolveAgentTools, resolveSubAgents, resolveTypeNode, scanTasks, upsertSkill };
1768
+ export { type AgentConfig, AgentCore, AgentMetadata, type ProdApp as App, AppRegistries, CorsOptions, type CreateAppOptions, CreateLoggerOptions, type CronScheduler, type DevApp, type FaapiConfig, FaapiContext, FaapiError, FaapiMiddleware, type FaapiPlugin, type HandlerTypeInfo, HelmetOptions, type InjectOptions, type InjectResponse, InjectorMap, InternalError, type LifecycleContext, type LifecycleHooks, type LlmConfig, type LlmModelConfig, LogConfig, Logger, type LoggerOptions, MethodNotAllowedError, ModuleLoadError, type PluginContext, type PluginDeclaration, type ProdApp, type PropertyType, type RequestHandler, type ResponseConfig, RouteManifest, RouteNotFoundError, type RouteSchemaSource, type RuntimeType, SchemaExtractionError, TASK_PATTERNS, type TaskBullMqOptions, TaskClient, type TaskConfig, TaskDriver, TaskFailedHandler, TaskManifest, type TaskPgBossOptions, TaskQueue, TaskRegistry, ToolMetadata, type ToolModule, type ToolSchemaModule, type TypeConstraint, type UpgradeHandler, ValidationError, type ValidationErrorCode, type ValidationIssue, type WsContext, type WsEventHandlers, type WsHandler, type WsSocket, clearAgentHandleFactory, collectRouteSchemaSources, configureLogging, createProdApp as createApp, createCronScheduler, createDevApp, createLogger, createProdApp, createProgram, createPrograms, createTaskQueue, extractTypeInfo, flushLogging, getAgent, getAgentEntry, getApp, getInputTypeForMethod, getSkill, getTool, getToolSchemaPath, hydrateSkillRegistry, invalidateProgramCache, listSkills, loadConfig, loadEnv, loadTaskDriver, loadToolModule, loadToolSchema, logger, readResource, registerAgentHandleFactory, removeSkill, resolveAgentTools, resolveSubAgents, resolveTypeNode, scanTasks, upsertSkill };