@faapi/faapi 6.22.0 → 6.24.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.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
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-CXWkRx4W.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-CXWkRx4W.js';
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-D1swYDVC.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-D1swYDVC.js';
3
3
  import * as node_http from 'node:http';
4
4
  import { Server, IncomingMessage, ServerResponse } from 'node:http';
5
5
  import { Socket } from 'node:net';
@@ -48,6 +48,14 @@ type UpgradeHandler = (req: IncomingMessage, socket: Socket, head: Buffer) => vo
48
48
  interface PluginContext {
49
49
  /** 项目根目录 */
50
50
  rootDir: string;
51
+ /**
52
+ * 产物 resources 目录绝对路径(`<rootDir>/<dist>/resources`)
53
+ *
54
+ * `src/resources/` 经 dev/build 复制进产物后的位置——插件 setup 时读静态
55
+ * 资源用;`@faapi/agent` 插件据此注入 AgentDeps(agent config 的
56
+ * systemPromptFile 相对此目录解析)。
57
+ */
58
+ resourcesDir: string;
51
59
  /** app 级注册表(tool/agent/skill/agentHandle 实例,随 app 生命周期) */
52
60
  registries: AppRegistries;
53
61
  /** 当前路由清单(setup 时的快照,reloadRoutes 后不会更新;需最新路由用 getRoutes()) */
@@ -251,6 +259,13 @@ interface TaskConfig {
251
259
  interface LifecycleContext {
252
260
  /** 项目根目录 */
253
261
  rootDir: string;
262
+ /**
263
+ * 运行时资源根目录绝对路径(<rootDir>/<dist>/resources)
264
+ *
265
+ * `src/resources/` 经 dev/build 复制进产物后的位置,onReady 中预加载
266
+ * prompt 模板等静态文件时定位用(`path.join(resourcesDir, 'prompts/foo.md')`)。
267
+ */
268
+ resourcesDir: string;
254
269
  /** 当前路由清单 */
255
270
  routes: RouteManifest;
256
271
  /** 服务器实例(onBoot 钩子触发时已创建但未监听,`listening === false`) */
@@ -843,6 +858,13 @@ interface WsContext {
843
858
  headers: Headers;
844
859
  /** 业务配置(来自 faapi.config.ts) */
845
860
  config: Record<string, unknown>;
861
+ /**
862
+ * 运行时资源根目录绝对路径(<rootDir>/<dist>/resources)
863
+ *
864
+ * 与 HTTP FaapiContext 同源(握手 ctx 是 FaapiContext 的结构子集),handler
865
+ * 的 WS 回调里读静态文件用。testing 直调未传时为 undefined。
866
+ */
867
+ resourcesDir?: string;
846
868
  /** 中间件塞入的用户信息(鉴权等) */
847
869
  user?: unknown;
848
870
  /** 允许通过 declare module 扩展 */
@@ -1244,52 +1266,6 @@ declare const TASK_PATTERNS: string[];
1244
1266
  */
1245
1267
  declare function scanTasks(rootDir: string, patterns: string[]): Promise<TaskManifest[]>;
1246
1268
 
1247
- /**
1248
- * 加载后的 agent 模块
1249
- *
1250
- * 与 [ToolModule](./loadToolModule.md) 对称——agent 的代码本体只有可选的 `run` 函数
1251
- * (自定义 agent 运行逻辑,替代默认 reactLoop)。
1252
- *
1253
- * > `config` 字段已移除——`AgentMetadata` 已含 AST 提取的字面量字段
1254
- * > (systemPrompt / tools / agents / model / maxTurns),`AgentModule.config`
1255
- * > 原本用于运行时拿到完整 config 对象(含动态字段),但 `executeSubAgent`
1256
- * > 拿到 `mod.config` 后从不读取(run 函数在自己模块内直接引用 config 变量),
1257
- * > 属于死链路,故移除。
1258
- *
1259
- * `AgentMetadata`(从 `faapi-agents.js` 水合)已含字面量字段,本模块仅用于
1260
- * 在运行时拿到 `run` 函数引用。
1261
- */
1262
- interface AgentModule {
1263
- /**
1264
- * 自定义 agent 运行函数(可选)
1265
- *
1266
- * `hasRun` 为 true 时一定为 function;为 false 时为 `undefined`。
1267
- * 调用方式由 `@faapi/agent` 子包的 Agent 类定义(Phase 3.x)。
1268
- */
1269
- run: ((...args: unknown[]) => unknown) | undefined;
1270
- }
1271
- /**
1272
- * 动态 import agent handler 文件并提取 `run` 导出
1273
- *
1274
- * Dev 按需编译模式(Vite 风格):先 `ensureCompiled` 确保产物存在再 import,
1275
- * 避免 import 不存在的文件污染 Vite SSR 内部状态(详见 [loadRouteModule](./loadRouteModule.md))。
1276
- * Prod 模式:产物在 build 阶段已固化,直接 import,失败即报错。
1277
- *
1278
- * 与 [loadToolModule](./loadToolModule.md) 的差异:
1279
- * - tool 按 `functionName` 提取单个函数(校验为 function)
1280
- * - agent 只提取 `run`(函数,可选)——config 块字段已在 AST 阶段提取为字面量,
1281
- * 运行时无需再加载 config 对象
1282
- *
1283
- * 错误传递:
1284
- * - 编译失败 → 抛 "Failed to compile agent module"
1285
- * - import 失败 → 抛 "Failed to load agent module"
1286
- *
1287
- * @param filePath agent handler 文件的绝对路径(产物形式,如 `dist/agents/researcher/handler.js`)
1288
- * @param hasRun 是否应提取 run 导出(来自 `AgentMetadata.hasRun`)
1289
- * @param rootDir 项目根目录(按需编译模式用,可选)
1290
- */
1291
- declare function loadAgentModule(filePath: string, hasRun: boolean, rootDir?: string): Promise<AgentModule>;
1292
-
1293
1269
  /**
1294
1270
  * 加载后的 tool 模块
1295
1271
  *
@@ -1368,14 +1344,14 @@ declare function loadToolSchema(tool: ToolMetadata, rootDir?: string): Promise<T
1368
1344
  /**
1369
1345
  * 按名查找单个 agent 的 LLM 可见元数据(默认实例)
1370
1346
  *
1371
- * 返回 [AgentCore](../ast/extractAgentMetadata.md)(不含 filePath / hasRun)。
1347
+ * 返回 [AgentCore](../ast/extractAgentMetadata.md)(不含 filePath)。
1372
1348
  * 加载 handler.js 执行 `run` 函数请用 [getAgentEntry](#getAgentEntry)。
1373
1349
  *
1374
1350
  * @param name agent 名(如 `researcher`,含 `@agent` 覆盖值)
1375
1351
  */
1376
1352
  declare function getAgent(name: string): AgentCore | undefined;
1377
1353
  /**
1378
- * 按名查找单个 agent 的完整元数据(默认实例,含 filePath / hasRun)
1354
+ * 按名查找单个 agent 的完整元数据(默认实例,含 filePath)
1379
1355
  */
1380
1356
  declare function getAgentEntry(name: string): AgentMetadata | undefined;
1381
1357
  /**
@@ -1681,6 +1657,21 @@ interface AppBase {
1681
1657
  wsRoutes: WsRouteManifest;
1682
1658
  /** 项目根目录 */
1683
1659
  rootDir: string;
1660
+ /**
1661
+ * 产物输出目录(相对 rootDir,如 '.faapi' 或 'dist')
1662
+ *
1663
+ * 与 createAppBase 内部解析一致:`options.dist ?? FAAPI_DIST ?? 'dist'`。
1664
+ * 业务方定位任意产物文件时与 rootDir 配合使用。
1665
+ */
1666
+ dist: string;
1667
+ /**
1668
+ * 运行时资源根目录绝对路径(<rootDir>/<dist>/resources)
1669
+ *
1670
+ * `src/resources/` 经 dev/build 复制进产物后的位置,业务方
1671
+ * `path.join(app.resourcesDir, 'prompts/foo.md')` 后自行读取。
1672
+ * 源码无 `src/resources/` 目录时路径仍指向约定位置(读文件由业务方容错)。
1673
+ */
1674
+ resourcesDir: string;
1684
1675
  /** 任务队列客户端(入队/查询;app 实例级,close 时随队列停机) */
1685
1676
  tasks: TaskClient;
1686
1677
  /** 启动 HTTP server,打印路由表,执行 onReady 钩子 */
@@ -1761,4 +1752,4 @@ type ProdApp = AppBase;
1761
1752
  */
1762
1753
  declare function createProdApp(options?: CreateAppOptions): Promise<ProdApp>;
1763
1754
 
1764
- 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 };
1755
+ 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, registerAgentHandleFactory, removeSkill, resolveAgentTools, resolveSubAgents, resolveTypeNode, scanTasks, upsertSkill };