@faapi/faapi 6.9.0 → 6.10.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/cli/index.js +45 -35
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +54 -21
- package/dist/index.js +49 -35
- package/dist/index.js.map +1 -1
- package/dist/{routeTypes-CuGMDCGB.d.ts → routeTypes-m9wZHWyo.d.ts} +9 -34
- package/dist/testing.d.ts +2 -4
- package/dist/testing.js +35 -33
- package/dist/testing.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,38 @@
|
|
|
1
|
-
import { A as AppRegistries, R as RouteManifest,
|
|
2
|
-
export {
|
|
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, 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, W as WsRouteManifest } from './routeTypes-m9wZHWyo.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 SseWriter, J as TaskContext, K as TaskDriverJob, M as TaskDriverProcess, N as TaskDriverRecord, O as TaskFailedInfo, P as TaskJob, Q as TaskJobStatus, U as TaskMetadata, V as TaskModule, X as TaskRegistriesSnapshot, Y as TaskRegistriesView, Z as ToolCore, _ as ToolPathMeta, $ as ToolRegistry, a0 as cors, a1 as createAppRegistries, a2 as createTaskRegistriesView, a3 as createTaskRegistry, a4 as helmet } from './routeTypes-m9wZHWyo.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';
|
|
6
6
|
import ts from 'typescript';
|
|
7
7
|
|
|
8
|
+
type LoggerFn = (messageOrObj: string | Record<string, unknown>, message?: string) => void;
|
|
9
|
+
interface LoggerOptions {
|
|
10
|
+
/**
|
|
11
|
+
* 自定义日志函数(完全接管输出,不再走统一管道——高级用法,一般无需配置)
|
|
12
|
+
*
|
|
13
|
+
* - 传入 `console.log`:纯文本格式 `GET /api/users 200 12ms`
|
|
14
|
+
* - 传入 pino logger:结构化日志 `logger.info({ method, path, status, durationMs }, 'request completed')`
|
|
15
|
+
*/
|
|
16
|
+
log?: LoggerFn;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 创建请求日志中间件(洋葱模型)
|
|
20
|
+
*
|
|
21
|
+
* 默认并入统一日志管道(egg 模型:访问日志与业务日志同管道,一份 config.log
|
|
22
|
+
* 管全部输出),`config.log.accessLog: false` 关闭。
|
|
23
|
+
*
|
|
24
|
+
* 日志格式(文本 message):GET /api/users 200 12ms
|
|
25
|
+
* 错误格式:POST /api/users 400 45ms - Error: ...
|
|
26
|
+
*
|
|
27
|
+
* before/after 一体,闭包变量共享开始时间,无需污染 ctx。
|
|
28
|
+
* 错误用 try/catch 捕获,记录后重新抛出(让上层处理)。
|
|
29
|
+
* 成功时从 next() 返回的 Response 读取状态码。
|
|
30
|
+
*
|
|
31
|
+
* log 函数每次请求时读取(options.log ?? defaultLog),运行时切换全局日志配置
|
|
32
|
+
* 同样生效。编程式自定义输出:`middlewares: [logger({ log: myFn })]`。
|
|
33
|
+
*/
|
|
34
|
+
declare function logger(options?: LoggerOptions): FaapiMiddleware;
|
|
35
|
+
|
|
8
36
|
/** HTTP 请求 handler 类型 */
|
|
9
37
|
type RequestHandler = (req: IncomingMessage, res: ServerResponse) => void;
|
|
10
38
|
/** WebSocket 升级 handler 类型 */
|
|
@@ -550,21 +578,19 @@ interface FaapiConfig {
|
|
|
550
578
|
etag?: EtagOptions | boolean;
|
|
551
579
|
/** 请求体大小限制(字节),默认 10MB(10 * 1024 * 1024) */
|
|
552
580
|
bodyLimit?: number;
|
|
553
|
-
/** 日志中间件配置 */
|
|
554
|
-
logger?: LoggerOptions | boolean;
|
|
555
581
|
/**
|
|
556
|
-
*
|
|
582
|
+
* 日志全局配置——唯一日志配置入口,业务日志与请求日志同管道(egg 模型,
|
|
583
|
+
* 详见 logger/logger.md;`config.logger` 独立配置已废除)
|
|
557
584
|
*
|
|
558
|
-
* - `false
|
|
559
|
-
* - `true` /
|
|
560
|
-
* - `LogConfig
|
|
561
|
-
*
|
|
562
|
-
* 两者互斥;`
|
|
563
|
-
*
|
|
585
|
+
* - `false`:全部静默(含 error 与请求日志,测试降噪)
|
|
586
|
+
* - `true` / 缺省:console 输出(consoleLevel 默认 'info'),管道不过滤
|
|
587
|
+
* - `LogConfig`:`dir` egg 风格文件输出(app.log 全量 + error.log 仅 error,
|
|
588
|
+
* splitByLevel 按级别四文件)或 `sink` 自定义管道接管(接 pino/winston),
|
|
589
|
+
* 两者互斥;`level` 管道阈值(不配不过滤)、`consoleLevel` console 出口阈值
|
|
590
|
+
* (不配 'info',false 关 console);请求日志无条件并入(`accessLog: false` 关闭)
|
|
564
591
|
*
|
|
565
|
-
* 生效范围:`ctx.log` / 参数注入 `log` / `createLogger` / `taskCtx.log
|
|
566
|
-
*
|
|
567
|
-
* 日志全局配置是进程级资源,多 app 同进程时后启动覆盖先启动。
|
|
592
|
+
* 生效范围:`ctx.log` / 参数注入 `log` / `createLogger` / `taskCtx.log` /
|
|
593
|
+
* 请求日志中间件。日志全局配置是进程级资源,多 app 同进程时后启动覆盖先启动。
|
|
568
594
|
*
|
|
569
595
|
* ```ts
|
|
570
596
|
* export default {
|
|
@@ -1495,16 +1521,23 @@ declare function loadEnv(rootDir: string): void;
|
|
|
1495
1521
|
/**
|
|
1496
1522
|
* 设置全局日志配置(进程级,`createAppBase` 启动时以 `config.log` 调用)
|
|
1497
1523
|
*
|
|
1498
|
-
* - `false
|
|
1499
|
-
* - `true` / `{}
|
|
1500
|
-
* - `{ level, sink }
|
|
1501
|
-
*
|
|
1524
|
+
* - `false`:全部静默(含 error 与请求日志,测试降噪场景)
|
|
1525
|
+
* - `true` / `{}`:console 出口默认 info,管道出口不过滤,无文件输出
|
|
1526
|
+
* - `{ level, consoleLevel, sink, dir, stdout, accessLog }`:egg 模型精细配置
|
|
1527
|
+
* (level 管管道出口、consoleLevel 管 console 出口;sink 与 dir 互斥)
|
|
1502
1528
|
* - `undefined`:重置为默认(编程式多 app 切换全局配置用)
|
|
1503
1529
|
*
|
|
1504
|
-
* LOG_LEVEL env
|
|
1505
|
-
*
|
|
1530
|
+
* LOG_LEVEL env 仅作为管道 level 的环境来源(consoleLevel 无 env)——本函数是
|
|
1531
|
+
* env 读取点,非法值启动期报错(fail fast)。
|
|
1506
1532
|
*/
|
|
1507
1533
|
declare function configureLogging(config?: LogConfig | boolean | undefined): void;
|
|
1534
|
+
/**
|
|
1535
|
+
* 刷盘文件日志缓冲(不结束流,flush 后可继续写)
|
|
1536
|
+
*
|
|
1537
|
+
* 优雅停机场景在 `lifecycle.onClose` 调用,确保缓冲中的条目落盘后再退出进程;
|
|
1538
|
+
* 测试场景断言文件内容前调用。无文件管道(未配置 `config.log.dir`)时为 no-op。
|
|
1539
|
+
*/
|
|
1540
|
+
declare function flushLogging(): Promise<void>;
|
|
1508
1541
|
/**
|
|
1509
1542
|
* 创建日志器
|
|
1510
1543
|
*
|
|
@@ -1713,4 +1746,4 @@ type ProdApp = AppBase;
|
|
|
1713
1746
|
*/
|
|
1714
1747
|
declare function createProdApp(options?: CreateAppOptions): Promise<ProdApp>;
|
|
1715
1748
|
|
|
1716
|
-
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, 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, getAgent, getAgentEntry, getApp, getInputTypeForMethod, getSkill, getTool, getToolSchemaPath, hydrateSkillRegistry, invalidateProgramCache, listSkills, loadAgentModule, loadConfig, loadEnv, loadTaskDriver, loadToolModule, loadToolSchema, registerAgentHandleFactory, removeSkill, resolveAgentTools, resolveSubAgents, resolveTypeNode, scanTasks, upsertSkill };
|
|
1749
|
+
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 };
|
package/dist/index.js
CHANGED
|
@@ -2374,7 +2374,15 @@ function assertLogLevel(value, source) {
|
|
|
2374
2374
|
);
|
|
2375
2375
|
}
|
|
2376
2376
|
}
|
|
2377
|
-
var globalState = {
|
|
2377
|
+
var globalState = {
|
|
2378
|
+
level: null,
|
|
2379
|
+
consoleLevel: null,
|
|
2380
|
+
sink: null,
|
|
2381
|
+
fileSink: null,
|
|
2382
|
+
stdout: true,
|
|
2383
|
+
accessLog: true,
|
|
2384
|
+
disabled: false
|
|
2385
|
+
};
|
|
2378
2386
|
function configureLogging(config) {
|
|
2379
2387
|
const objectConfig = typeof config === "object" ? config : {};
|
|
2380
2388
|
if (objectConfig.sink && objectConfig.dir) {
|
|
@@ -2385,9 +2393,17 @@ function configureLogging(config) {
|
|
|
2385
2393
|
void globalState.fileSink?.close();
|
|
2386
2394
|
globalState.disabled = config === false;
|
|
2387
2395
|
globalState.sink = objectConfig.sink ?? null;
|
|
2388
|
-
globalState.accessLog = objectConfig.accessLog ??
|
|
2396
|
+
globalState.accessLog = objectConfig.accessLog ?? true;
|
|
2389
2397
|
globalState.stdout = objectConfig.stdout ?? true;
|
|
2390
2398
|
globalState.fileSink = objectConfig.dir ? createFileLogSink({ dir: objectConfig.dir, splitByLevel: objectConfig.splitByLevel }) : null;
|
|
2399
|
+
if (objectConfig.consoleLevel !== void 0) {
|
|
2400
|
+
if (objectConfig.consoleLevel !== false) {
|
|
2401
|
+
assertLogLevel(objectConfig.consoleLevel, "config.log.consoleLevel");
|
|
2402
|
+
}
|
|
2403
|
+
globalState.consoleLevel = objectConfig.consoleLevel;
|
|
2404
|
+
} else {
|
|
2405
|
+
globalState.consoleLevel = null;
|
|
2406
|
+
}
|
|
2391
2407
|
if (objectConfig.level !== void 0) {
|
|
2392
2408
|
assertLogLevel(objectConfig.level, "config.log.level");
|
|
2393
2409
|
globalState.level = objectConfig.level;
|
|
@@ -2398,52 +2414,57 @@ function configureLogging(config) {
|
|
|
2398
2414
|
globalState.level = null;
|
|
2399
2415
|
}
|
|
2400
2416
|
}
|
|
2401
|
-
function
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2417
|
+
function pipelineThreshold() {
|
|
2418
|
+
return globalState.level ?? void 0;
|
|
2419
|
+
}
|
|
2420
|
+
function consoleThreshold() {
|
|
2421
|
+
return globalState.consoleLevel ?? "info";
|
|
2405
2422
|
}
|
|
2406
2423
|
function belowThreshold(level, threshold) {
|
|
2407
2424
|
return threshold !== void 0 && LEVEL_RANK[level] < LEVEL_RANK[threshold];
|
|
2408
2425
|
}
|
|
2409
2426
|
function getEffectiveLogLevel() {
|
|
2410
|
-
return
|
|
2427
|
+
return pipelineThreshold();
|
|
2411
2428
|
}
|
|
2412
|
-
var consoleSink = (entry) => {
|
|
2413
|
-
console[CONSOLE_METHOD[entry.level]](formatEntry(entry));
|
|
2414
|
-
};
|
|
2415
2429
|
var CONSOLE_METHOD = {
|
|
2416
2430
|
debug: "debug",
|
|
2417
2431
|
info: "info",
|
|
2418
2432
|
warn: "warn",
|
|
2419
2433
|
error: "error"
|
|
2420
2434
|
};
|
|
2435
|
+
function consoleDispatch(entry) {
|
|
2436
|
+
const threshold = consoleThreshold();
|
|
2437
|
+
if (threshold === false || belowThreshold(entry.level, threshold)) return;
|
|
2438
|
+
console[CONSOLE_METHOD[entry.level]](formatEntry(entry));
|
|
2439
|
+
}
|
|
2421
2440
|
function globalDispatch(entry) {
|
|
2422
2441
|
if (globalState.disabled) return;
|
|
2442
|
+
const pipeThreshold = pipelineThreshold();
|
|
2423
2443
|
if (globalState.sink) {
|
|
2424
|
-
globalState.sink(entry);
|
|
2444
|
+
if (!belowThreshold(entry.level, pipeThreshold)) globalState.sink(entry);
|
|
2425
2445
|
return;
|
|
2426
2446
|
}
|
|
2427
2447
|
if (globalState.fileSink) {
|
|
2428
|
-
globalState.fileSink.write(entry);
|
|
2429
|
-
if (globalState.stdout)
|
|
2448
|
+
if (!belowThreshold(entry.level, pipeThreshold)) globalState.fileSink.write(entry);
|
|
2449
|
+
if (globalState.stdout) consoleDispatch(entry);
|
|
2430
2450
|
return;
|
|
2431
2451
|
}
|
|
2432
|
-
|
|
2452
|
+
consoleDispatch(entry);
|
|
2433
2453
|
}
|
|
2434
2454
|
function writeLogEntry(entry) {
|
|
2435
|
-
if (belowThreshold(entry.level, globalThreshold())) return;
|
|
2436
2455
|
globalDispatch(entry);
|
|
2437
2456
|
}
|
|
2438
|
-
function
|
|
2457
|
+
function flushLogging() {
|
|
2458
|
+
return globalState.fileSink ? globalState.fileSink.flush() : Promise.resolve();
|
|
2459
|
+
}
|
|
2460
|
+
function isAccessLogEnabled() {
|
|
2439
2461
|
return !globalState.disabled && globalState.accessLog;
|
|
2440
2462
|
}
|
|
2441
2463
|
function createLogger(scope, options) {
|
|
2442
2464
|
const baseScope = scope;
|
|
2443
2465
|
const baseFields = options?.fields;
|
|
2444
2466
|
const write = (level, message, callFields, scopeSuffix) => {
|
|
2445
|
-
|
|
2446
|
-
if (belowThreshold(level, threshold)) return;
|
|
2467
|
+
if (belowThreshold(level, options?.level)) return;
|
|
2447
2468
|
const entry = {
|
|
2448
2469
|
level,
|
|
2449
2470
|
message,
|
|
@@ -4014,18 +4035,14 @@ function levelForStatus(status) {
|
|
|
4014
4035
|
return "info";
|
|
4015
4036
|
}
|
|
4016
4037
|
function defaultLog(entry, text) {
|
|
4017
|
-
if (
|
|
4018
|
-
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
|
|
4022
|
-
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
writeLogEntry(logEntry);
|
|
4026
|
-
return;
|
|
4027
|
-
}
|
|
4028
|
-
console.log(entry);
|
|
4038
|
+
if (!isAccessLogEnabled()) return;
|
|
4039
|
+
writeLogEntry({
|
|
4040
|
+
level: levelForStatus(entry.status),
|
|
4041
|
+
message: text,
|
|
4042
|
+
time: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4043
|
+
scope: "access",
|
|
4044
|
+
fields: entry
|
|
4045
|
+
});
|
|
4029
4046
|
}
|
|
4030
4047
|
function logger(options = {}) {
|
|
4031
4048
|
return async (ctx, next) => {
|
|
@@ -5938,7 +5955,6 @@ function createServer(options) {
|
|
|
5938
5955
|
compression: compressionOption,
|
|
5939
5956
|
etag: etagOption,
|
|
5940
5957
|
registries,
|
|
5941
|
-
logger: loggerOption,
|
|
5942
5958
|
bodyLimit = DEFAULT_BODY_LIMIT,
|
|
5943
5959
|
http2: http2Option,
|
|
5944
5960
|
trustedProxy = false
|
|
@@ -5955,8 +5971,7 @@ function createServer(options) {
|
|
|
5955
5971
|
const helmOpts = typeof helmetOption === "object" ? helmetOption : {};
|
|
5956
5972
|
configMiddlewares.push(helmet(helmOpts));
|
|
5957
5973
|
}
|
|
5958
|
-
|
|
5959
|
-
if (loggerMiddlewareInst) configMiddlewares.push(loggerMiddlewareInst);
|
|
5974
|
+
configMiddlewares.push(logger());
|
|
5960
5975
|
if (etagOption) {
|
|
5961
5976
|
const etagOpts = typeof etagOption === "object" ? etagOption : {};
|
|
5962
5977
|
configMiddlewares.push(etag(etagOpts));
|
|
@@ -6938,7 +6953,6 @@ var FAAPI_CONFIG_KEYS = /* @__PURE__ */ new Set([
|
|
|
6938
6953
|
"compression",
|
|
6939
6954
|
"etag",
|
|
6940
6955
|
"bodyLimit",
|
|
6941
|
-
"logger",
|
|
6942
6956
|
"log",
|
|
6943
6957
|
"http2",
|
|
6944
6958
|
"trustedProxy",
|
|
@@ -7013,7 +7027,6 @@ async function createAppBase(options) {
|
|
|
7013
7027
|
helmet: config?.helmet,
|
|
7014
7028
|
compression: config?.compression,
|
|
7015
7029
|
etag: config?.etag,
|
|
7016
|
-
logger: config?.logger,
|
|
7017
7030
|
bodyLimit: config?.bodyLimit,
|
|
7018
7031
|
http2: config?.http2,
|
|
7019
7032
|
trustedProxy: config?.trustedProxy,
|
|
@@ -7671,6 +7684,7 @@ export {
|
|
|
7671
7684
|
createTaskRegistriesView,
|
|
7672
7685
|
createTaskRegistry,
|
|
7673
7686
|
extractTypeInfo,
|
|
7687
|
+
flushLogging,
|
|
7674
7688
|
getAgent,
|
|
7675
7689
|
getAgentEntry,
|
|
7676
7690
|
getApp,
|