@faapi/faapi 3.2.0 → 3.3.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 +657 -413
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +63 -6
- package/dist/index.js +549 -303
- package/dist/index.js.map +1 -1
- package/dist/testing.js +473 -239
- package/dist/testing.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -308,6 +308,9 @@ interface AgentConfig {
|
|
|
308
308
|
* Phase 2.3 的 `agent` 参数注入暂返回 `undefined`,Phase 3.x 的 @faapi/agent 插件
|
|
309
309
|
* 读取此值从 [agentRegistry](../injection/agentRegistry.md) 查找对应 agent 元数据,
|
|
310
310
|
* 注入 `AgentHandle`(含可调用 `run`)。
|
|
311
|
+
*
|
|
312
|
+
* 可选——未设时 handler 需通过 `agent.run(input, { agent: 'name' })` 显式指定 agent 名,
|
|
313
|
+
* 否则 `agent.run` 抛 `AgentError`。
|
|
311
314
|
*/
|
|
312
315
|
defaultAgent?: string;
|
|
313
316
|
/**
|
|
@@ -323,22 +326,23 @@ interface AgentConfig {
|
|
|
323
326
|
*/
|
|
324
327
|
maxAgentDepth?: number;
|
|
325
328
|
/**
|
|
326
|
-
* 启用 tracing 的全局默认值(默认
|
|
329
|
+
* 启用 tracing 的全局默认值(默认 false——opt-in,不开启零开销)
|
|
327
330
|
*
|
|
328
331
|
* 开启时 `agent.run()` / `agent.stream()` 返回的 `result.trace` /
|
|
329
332
|
* `chunk.traceEvent` 填充结构化调用明细(按轮次组织的 LLM 调用、tool 调用、
|
|
330
333
|
* sub-agent 嵌套调用事件,含 timing 与 token 用量)。
|
|
331
334
|
*
|
|
332
335
|
* 三层覆盖优先级:`AgentRunOptions.enableTracing` > agent 自身配置 >
|
|
333
|
-
* 此全局配置 > 默认 `
|
|
336
|
+
* 此全局配置 > 默认 `false`。
|
|
334
337
|
*
|
|
335
|
-
*
|
|
338
|
+
* tracing 采集每轮 LLM 消息快照与 tool 明细,有真实内存/CPU 开销——
|
|
339
|
+
* 需要观测的端点显式开启:
|
|
336
340
|
*
|
|
337
341
|
* ```ts
|
|
338
342
|
* import type { FaapiConfig } from '@faapi/faapi';
|
|
339
343
|
* export default {
|
|
340
344
|
* agent: {
|
|
341
|
-
* enableTracing:
|
|
345
|
+
* enableTracing: true, // 全局开启;单次调用可用 run(input, { enableTracing: true }) 覆盖
|
|
342
346
|
* llms: { openai: { provider: 'openai', apiKey: '...', models: { 'gpt-4o': {} } } },
|
|
343
347
|
* },
|
|
344
348
|
* } satisfies FaapiConfig;
|
|
@@ -390,6 +394,15 @@ interface FaapiConfig {
|
|
|
390
394
|
logger?: LoggerOptions | boolean;
|
|
391
395
|
/** HTTP/2 配置,false 禁用(默认 http/1.1) */
|
|
392
396
|
http2?: Http2Options | boolean;
|
|
397
|
+
/**
|
|
398
|
+
* 是否信任反向代理头(X-Forwarded-For),默认 false
|
|
399
|
+
*
|
|
400
|
+
* - `true`:`ctx.ip` 取 `x-forwarded-for` 第一个 IP——部署在 nginx/CDN 等受信任
|
|
401
|
+
* 反向代理之后时开启
|
|
402
|
+
* - `false`(默认):直取 socket 地址。客户端直连时 XFF 可被任意伪造,
|
|
403
|
+
* 安全默认不信任(同时影响 HTTP 与 WS 握手的 `ctx.ip`)
|
|
404
|
+
*/
|
|
405
|
+
trustedProxy?: boolean;
|
|
393
406
|
/**
|
|
394
407
|
* 统一响应包装配置
|
|
395
408
|
*
|
|
@@ -607,20 +620,54 @@ interface WsContext {
|
|
|
607
620
|
type WsHandler = (ctx: WsContext) => WsEventHandlers | void;
|
|
608
621
|
|
|
609
622
|
/**
|
|
610
|
-
* 清理所有 Program
|
|
623
|
+
* 清理所有 Program 缓存 + tsconfig 解析缓存(watch 模式下文件变化时调用)
|
|
611
624
|
*
|
|
612
625
|
* 全量清理而非增量清理,理由:
|
|
613
626
|
* - 简单可靠,无状态一致性问题
|
|
614
627
|
* - 跨文件类型引用需要所有文件的 Program 同步更新
|
|
628
|
+
* - tsconfig 可能变化,需重新读取
|
|
615
629
|
* - dev 模式文件量有限,全量重建在百毫秒级
|
|
616
630
|
*/
|
|
617
631
|
declare function invalidateProgramCache(): void;
|
|
618
632
|
/**
|
|
619
633
|
* 为指定文件创建 TypeScript Program(带缓存)
|
|
620
634
|
*
|
|
635
|
+
* 从 filePath 向上查找最近的 tsconfig.json:
|
|
636
|
+
* - 找到:用 ts.parseJsonConfigFileContent 解析,取 module / moduleResolution
|
|
637
|
+
* 覆盖默认值,同时取 parsed.fileNames 作为 program 的 rootNames(让跨文件
|
|
638
|
+
* import 的源文件被加载进 program)
|
|
639
|
+
* - 找不到(如 os.tmpdir() 测试场景):回退到默认 NodeNext,rootNames 仅包含 filePath
|
|
640
|
+
*
|
|
641
|
+
* 加载全部相关文件保证 `resolveTypeReference` 的兜底遍历(找同名声明)能成功,
|
|
642
|
+
* 修复业务项目用 `moduleResolution: Bundler` + 无扩展名相对导入时跨文件
|
|
643
|
+
* `import type` 解析失败的问题。
|
|
644
|
+
*
|
|
645
|
+
* 同一次生成中需要分析多个文件时用 {@link createPrograms}(按 tsconfig 分组共享
|
|
646
|
+
* 同一个 Program),避免每个文件单独创建 Program 重复解析全项目源码。
|
|
647
|
+
*
|
|
621
648
|
* @param filePath 要分析的 .ts 文件绝对路径
|
|
622
649
|
*/
|
|
623
650
|
declare function createProgram(filePath: string): ts.Program;
|
|
651
|
+
/**
|
|
652
|
+
* 为多个文件创建 Program(按 tsconfig 分组共享,带缓存)
|
|
653
|
+
*
|
|
654
|
+
* 同一次批量提取(build 时生成 routes/tools/agents 产物)中,所有向上查找到
|
|
655
|
+
* 同一个 tsconfig.json 的文件共用**同一个 Program**——rootNames 为
|
|
656
|
+
* tsconfig fileNames ∪ 全部入口文件,跨文件类型解析语义与单文件 `createProgram`
|
|
657
|
+
* 完全一致,但 N 个文件只创建 1 个 Program(原来每个文件都全量解析一遍项目源码,
|
|
658
|
+
* 是 build 时间的最大单项开销)。
|
|
659
|
+
*
|
|
660
|
+
* 缓存 key 为 `shared::<tsconfigPath>::<排序后的文件列表>`:同一批次重复调用命中
|
|
661
|
+
* 缓存;不同批次(rootNames 不同)各自创建。`invalidateProgramCache()` 同时清理
|
|
662
|
+
* 共享缓存与单文件缓存。
|
|
663
|
+
*
|
|
664
|
+
* 向上查找不到 tsconfig.json 的文件(如 os.tmpdir() 测试场景)逐个回退到
|
|
665
|
+
* {@link createProgram} 单文件行为,不参与共享。
|
|
666
|
+
*
|
|
667
|
+
* @param filePaths 要分析的 .ts 文件绝对路径列表(内部去重)
|
|
668
|
+
* @returns filePath → Program 映射(包含全部请求文件)
|
|
669
|
+
*/
|
|
670
|
+
declare function createPrograms(filePaths: string[]): Map<string, ts.Program>;
|
|
624
671
|
|
|
625
672
|
/**
|
|
626
673
|
* Schema 提取错误
|
|
@@ -1181,6 +1228,16 @@ interface ToolSchemaModule {
|
|
|
1181
1228
|
/** schema 导出名(如 `WeatherInputSchema`,用于日志/调试) */
|
|
1182
1229
|
schemaName: string;
|
|
1183
1230
|
}
|
|
1231
|
+
/**
|
|
1232
|
+
* 计算 tool 的 zod.js 绝对路径(纯路径计算,无 fs 访问)
|
|
1233
|
+
*
|
|
1234
|
+
* 与 [loadToolSchema](./loadToolSchema.ts) 内部使用的路径逻辑同源(共享 `getDist()`),
|
|
1235
|
+
* 供 `@faapi/agent` 的跨请求 schema 缓存用作缓存键 + mtime 校验目标。
|
|
1236
|
+
*
|
|
1237
|
+
* @param tool tool 元数据(含 `filePath`)
|
|
1238
|
+
* @param rootDir 项目根目录(`tool.filePath` 是相对路径时拼接)
|
|
1239
|
+
*/
|
|
1240
|
+
declare function getToolSchemaPath(tool: ToolMetadata, rootDir?: string): string;
|
|
1184
1241
|
/**
|
|
1185
1242
|
* 动态加载 tool 的 zod.js schema 模块
|
|
1186
1243
|
*
|
|
@@ -1509,4 +1566,4 @@ type ProdApp = AppBase;
|
|
|
1509
1566
|
*/
|
|
1510
1567
|
declare function createProdApp(options?: CreateAppOptions): Promise<ProdApp>;
|
|
1511
1568
|
|
|
1512
|
-
export { type AgentConfig, type AgentCore, type AgentHandleFactory, type AgentMetadata, type AgentModule, type AgentPathMeta, type AgentToolDescriptor, type ProdApp as App, CorsOptions, type CreateAppOptions, 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, type ToolCore, type ToolMetadata, type ToolModule, type ToolPathMeta, type ToolSchemaModule, type TypeConstraint, type UpgradeHandler, ValidationError, type ValidationErrorCode, type ValidationIssue, type WsContext, type WsEventHandlers, type WsHandler, type WsSocket, clearAgentHandleFactory, collectRouteSchemaSources, createProdApp as createApp, createDevApp, createProdApp, createProgram, extractTypeInfo, getAgent, getAgentEntry, getApp, getInputTypeForMethod, getSkill, getTool, hydrateSkillRegistry, invalidateProgramCache, listSkills, loadAgentModule, loadConfig, loadEnv, loadToolModule, loadToolSchema, registerAgentHandleFactory, removeSkill, resolveAgentTools, resolveSubAgents, resolveTypeNode, upsertSkill };
|
|
1569
|
+
export { type AgentConfig, type AgentCore, type AgentHandleFactory, type AgentMetadata, type AgentModule, type AgentPathMeta, type AgentToolDescriptor, type ProdApp as App, CorsOptions, type CreateAppOptions, 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, type ToolCore, type ToolMetadata, type ToolModule, type ToolPathMeta, type ToolSchemaModule, type TypeConstraint, type UpgradeHandler, ValidationError, type ValidationErrorCode, type ValidationIssue, type WsContext, type WsEventHandlers, type WsHandler, type WsSocket, clearAgentHandleFactory, collectRouteSchemaSources, createProdApp as createApp, createDevApp, createProdApp, createProgram, createPrograms, extractTypeInfo, getAgent, getAgentEntry, getApp, getInputTypeForMethod, getSkill, getTool, getToolSchemaPath, hydrateSkillRegistry, invalidateProgramCache, listSkills, loadAgentModule, loadConfig, loadEnv, loadToolModule, loadToolSchema, registerAgentHandleFactory, removeSkill, resolveAgentTools, resolveSubAgents, resolveTypeNode, upsertSkill };
|