@faapi/faapi 6.3.0 → 6.4.1
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/cli/index.js +302 -156
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +68 -28
- package/dist/index.js +293 -153
- package/dist/index.js.map +1 -1
- package/dist/{routeTypes-CCveqSnY.d.ts → routeTypes-_17rXzal.d.ts} +152 -11
- package/dist/testing.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { A as AppRegistries, R as RouteManifest, F as FaapiContext, C as CorsOptions, T as TaskClient, H as HelmetOptions, L as LoggerOptions, a as FaapiMiddleware, I as InjectorMap, b as
|
|
2
|
-
export {
|
|
1
|
+
import { A as AppRegistries, R as RouteManifest, F as FaapiContext, C as CorsOptions, T as TaskClient, H as HelmetOptions, L as LoggerOptions, a as FaapiMiddleware, I as InjectorMap, b as TaskFailedHandler, c as TaskQueueDeps, d as TaskQueue, e as TaskDriver, f as TaskRegistry, g as TaskManifest, h as ToolMetadata, i as AgentCore, j as AgentMetadata, W as WsRouteManifest } from './routeTypes-_17rXzal.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 Injector, t as RouteInfo, u as RouteInputSchema, v as RouteOutputSchema, w as RouteParamSchema, S as SkillRegistry, x as SseEvent, y as SseWriter, z as TaskContext, B as TaskDriverJob, D as TaskDriverProcess, E as TaskDriverRecord, G as TaskFailedInfo, J as TaskJob, K as TaskJobStatus, M as TaskMetadata, N as TaskModule, O as ToolCore, P as ToolPathMeta, Q as ToolRegistry, U as cors, V as createAppRegistries, X as createTaskRegistry, Y as helmet, Z as logger } from './routeTypes-_17rXzal.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';
|
|
@@ -157,13 +157,50 @@ interface LifecycleHooks {
|
|
|
157
157
|
onError?: (error: unknown, ctx: FaapiContext) => Promise<void> | void;
|
|
158
158
|
}
|
|
159
159
|
/**
|
|
160
|
-
*
|
|
160
|
+
* pg-boss 驱动选项(透传给 @faapi/task-pgboss)
|
|
161
161
|
*
|
|
162
|
-
*
|
|
162
|
+
* 主包不依赖 pg-boss,这里只声明常用连接字段的透传形状;完整项见 pg-boss 文档
|
|
163
|
+
* (ConstructorOptions)。
|
|
164
|
+
*/
|
|
165
|
+
interface TaskPgBossOptions {
|
|
166
|
+
/** PostgreSQL 连接串(如 `postgres://localhost:5432/app`) */
|
|
167
|
+
connectionString?: string;
|
|
168
|
+
/** 其余 pg-boss ConstructorOptions 字段原样透传 */
|
|
169
|
+
[key: string]: unknown;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* BullMQ 驱动选项(透传给 @faapi/task-bullmq)
|
|
173
|
+
*/
|
|
174
|
+
interface TaskBullMqOptions {
|
|
175
|
+
/** Redis 连接配置(透传给 Queue / Worker 的 connection) */
|
|
176
|
+
connection?: {
|
|
177
|
+
host?: string;
|
|
178
|
+
port?: number;
|
|
179
|
+
password?: string;
|
|
180
|
+
db?: number;
|
|
181
|
+
[key: string]: unknown;
|
|
182
|
+
};
|
|
183
|
+
/** 队列名前缀(默认 `faapi`——同一 Redis 下多个 faapi 应用隔离用) */
|
|
184
|
+
prefix?: string;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* 任务子系统配置
|
|
188
|
+
*
|
|
189
|
+
* 任务队列由持久化驱动承载(内置 memory 驱动已移除):存在任务清单
|
|
190
|
+
* (`src/tasks/` 下的 task.ts)时必须显式配置 `driver`,否则启动报错;
|
|
191
|
+
* 无任务清单的项目不加载驱动(零任务项目无需安装驱动子包)。
|
|
163
192
|
*/
|
|
164
193
|
interface TaskConfig {
|
|
165
|
-
/**
|
|
166
|
-
|
|
194
|
+
/**
|
|
195
|
+
* 队列驱动:'pgboss'(@faapi/task-pgboss,Postgres)| 'bullmq'(@faapi/task-bullmq,Redis)
|
|
196
|
+
*
|
|
197
|
+
* 有任务清单时必填;也可在编程式场景传入自定义 TaskDriver 实例
|
|
198
|
+
*/
|
|
199
|
+
driver?: 'pgboss' | 'bullmq';
|
|
200
|
+
/** `driver: 'pgboss'` 时的选项(透传给 @faapi/task-pgboss) */
|
|
201
|
+
pgboss?: TaskPgBossOptions;
|
|
202
|
+
/** `driver: 'bullmq'` 时的选项(透传给 @faapi/task-bullmq) */
|
|
203
|
+
bullmq?: TaskBullMqOptions;
|
|
167
204
|
/**
|
|
168
205
|
* 是否启动任务队列(默认 true)
|
|
169
206
|
*
|
|
@@ -173,6 +210,12 @@ interface TaskConfig {
|
|
|
173
210
|
enabled?: boolean;
|
|
174
211
|
/** 优雅停机时等待在跑任务的最长时间(毫秒,默认 10000;超时 abort) */
|
|
175
212
|
shutdownTimeoutMs?: number;
|
|
213
|
+
/**
|
|
214
|
+
* 任务执行失败/取消钩子——每次 process 抛错后触发(含将重试的失败),
|
|
215
|
+
* `info.willRetry` 按任务 meta.retries 推算、`info.cancelled` 标记框架终止;
|
|
216
|
+
* 用于告警/死信上报等副作用,自身抛错被忽略
|
|
217
|
+
*/
|
|
218
|
+
onFailed?: TaskFailedHandler;
|
|
176
219
|
}
|
|
177
220
|
/**
|
|
178
221
|
* 生命周期上下文
|
|
@@ -1087,47 +1130,37 @@ declare function collectRouteSchemaSources(routes: RouteManifest, rootDir?: stri
|
|
|
1087
1130
|
* 职责边界(driverTypes.md):
|
|
1088
1131
|
* - 本层:任务存在性检查 → payload zod 校验 → 驱动入队;worker 执行包装
|
|
1089
1132
|
* (模块加载 + run 调用 + 任务记录更新);start/stop/reload 生命周期编排
|
|
1090
|
-
* - 驱动层(deps.driver
|
|
1133
|
+
* - 驱动层(deps.driver,必填——持久化驱动子包或自定义 TaskDriver):
|
|
1134
|
+
* 入队存储、worker 消费、重试策略、停机 drain
|
|
1091
1135
|
*
|
|
1092
1136
|
* 任务记录(list)由本层维护:enqueue 写 pending,每次 process 写 attempts/running,
|
|
1093
1137
|
* 返回写 done,抛错写 failed——对任何驱动语义一致。
|
|
1094
1138
|
*/
|
|
1095
1139
|
declare function createTaskQueue(deps: TaskQueueDeps): TaskQueue;
|
|
1096
1140
|
|
|
1097
|
-
/**
|
|
1098
|
-
* 进程内内存驱动(TaskDriver 默认实现,零依赖)
|
|
1099
|
-
*
|
|
1100
|
-
* 行为与第一版内存队列一致(taskQueue 重构前的原始语义):
|
|
1101
|
-
* - 入队进每任务 FIFO 数组;延迟任务由 runAt 控制
|
|
1102
|
-
* - 每任务最多 concurrency 个并行(startWorker 注册时给定)
|
|
1103
|
-
* - 失败按 retries 指数退避重试(500ms * 2^(n-1),封顶 30s);耗尽后丢弃(失败记录由语义层在最后一次 process 抛错时写入)
|
|
1104
|
-
* - stop(timeoutMs):停止出队 + 停接受新任务,等在跑任务,超时 abort;重试等待中的任务取消(视为失败)
|
|
1105
|
-
*
|
|
1106
|
-
* 取舍不变:重启即丢、多实例不防重跑(fallback.md)。
|
|
1107
|
-
*/
|
|
1108
|
-
declare function createMemoryDriver(): TaskDriver;
|
|
1109
|
-
|
|
1110
1141
|
/**
|
|
1111
1142
|
* 按 config.task.driver 解析并加载任务队列驱动
|
|
1112
1143
|
*
|
|
1113
|
-
* - 未设置 / `'memory'` → 内置 memoryDriver(零依赖)
|
|
1114
1144
|
* - `'pgboss'` → 动态加载子包 `@faapi/task-pgboss` 的 `createPgBossDriver(options)`
|
|
1115
1145
|
* - `'bullmq'` → 动态加载子包 `@faapi/task-bullmq` 的 `createBullMQDriver(options)`
|
|
1116
1146
|
* - TaskDriver 对象 → 直接使用(编程式自定义驱动)
|
|
1117
|
-
* - 其他值 → 显式抛错,不静默降级
|
|
1147
|
+
* - `undefined` / `'memory'` / 其他值 → 显式抛错,不静默降级
|
|
1148
|
+
*
|
|
1149
|
+
* 内置 memory 驱动已移除——任务队列由持久化/外部驱动承载;未配置 driver 时
|
|
1150
|
+
* createAppBase 仅在存在任务清单时报错(无任务项目用 idleTaskDriver,不调用本函数)。
|
|
1118
1151
|
*
|
|
1119
1152
|
* 子包 specifier 用变量拼接(`'@faapi/task-' + name`)而非字面量——主包不依赖
|
|
1120
1153
|
* 驱动子包,运行时从业务方 node_modules 解析(与 zod peerDependency 同策略)。
|
|
1121
|
-
*
|
|
1154
|
+
* 未安装时抛出带安装指引的错误。
|
|
1122
1155
|
*/
|
|
1123
1156
|
declare function loadTaskDriver(driver: string | TaskDriver | undefined, driverOptions: unknown): Promise<TaskDriver>;
|
|
1124
1157
|
|
|
1125
1158
|
/**
|
|
1126
1159
|
* cron 定时入队调度器
|
|
1127
1160
|
*
|
|
1128
|
-
* 为注册表中声明了 `cron` 的任务建立 croner 定时器,到点调用
|
|
1129
|
-
* 投递空 payload——定时只是"自动投递者"
|
|
1130
|
-
*
|
|
1161
|
+
* 为注册表中声明了 `cron` 的任务建立 croner 定时器,到点调用
|
|
1162
|
+
* `enqueue(name, { dedupId })` 投递空 payload——定时只是"自动投递者",
|
|
1163
|
+
* 复用队列的重试/并发/停机语义。详见 cronScheduler.md。
|
|
1131
1164
|
*/
|
|
1132
1165
|
interface CronScheduler {
|
|
1133
1166
|
/** 建立全部 cron 定时器(幂等——重复调用先清理旧定时器) */
|
|
@@ -1135,7 +1168,14 @@ interface CronScheduler {
|
|
|
1135
1168
|
/** 停止全部定时器(幂等) */
|
|
1136
1169
|
stop(): void;
|
|
1137
1170
|
}
|
|
1138
|
-
|
|
1171
|
+
/**
|
|
1172
|
+
* cron 投递回调:opts.dedupId 为多实例防重幂等键
|
|
1173
|
+
* (`cron:<任务名>:<计划触发时刻>`——各实例同一触发窗算出同键,驱动按键去重)
|
|
1174
|
+
*/
|
|
1175
|
+
type CronEnqueue = (name: string, opts: {
|
|
1176
|
+
dedupId?: string;
|
|
1177
|
+
}) => Promise<unknown>;
|
|
1178
|
+
declare function createCronScheduler(registry: TaskRegistry, enqueue: CronEnqueue): CronScheduler;
|
|
1139
1179
|
|
|
1140
1180
|
/**
|
|
1141
1181
|
* 任务扫描 patterns(框架约定,非用户可配置项)
|
|
@@ -1626,4 +1666,4 @@ type ProdApp = AppBase;
|
|
|
1626
1666
|
*/
|
|
1627
1667
|
declare function createProdApp(options?: CreateAppOptions): Promise<ProdApp>;
|
|
1628
1668
|
|
|
1629
|
-
export { type AgentConfig, AgentCore, AgentMetadata, type AgentModule, type ProdApp as App, AppRegistries, CorsOptions, type CreateAppOptions, 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, LoggerOptions, MethodNotAllowedError, ModuleLoadError, type PluginContext, type PluginDeclaration, type ProdApp, type PropertyType, type RequestHandler, type ResponseConfig, RouteManifest, RouteNotFoundError, type RouteSchemaSource, type RuntimeType, SchemaExtractionError, TASK_PATTERNS, TaskClient, TaskDriver, TaskManifest, 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, createProdApp as createApp, createCronScheduler, createDevApp,
|
|
1669
|
+
export { type AgentConfig, AgentCore, AgentMetadata, type AgentModule, type ProdApp as App, AppRegistries, CorsOptions, type CreateAppOptions, 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, 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, createProdApp as createApp, createCronScheduler, createDevApp, createProdApp, createProgram, createPrograms, createTaskQueue, extractTypeInfo, getAgent, getAgentEntry, getApp, getInputTypeForMethod, getSkill, getTool, getToolSchemaPath, hydrateSkillRegistry, invalidateProgramCache, listSkills, loadAgentModule, loadConfig, loadEnv, loadTaskDriver, loadToolModule, loadToolSchema, registerAgentHandleFactory, removeSkill, resolveAgentTools, resolveSubAgents, resolveTypeNode, scanTasks, upsertSkill };
|