@faapi/faapi 3.1.0 → 3.2.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 +497 -361
- package/dist/cli/index.js.map +1 -1
- package/dist/index.d.ts +45 -12
- package/dist/index.js +406 -266
- package/dist/index.js.map +1 -1
- package/dist/testing.js +305 -172
- package/dist/testing.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -322,6 +322,31 @@ interface AgentConfig {
|
|
|
322
322
|
* 默认值由 Phase 3.x 的 @faapi/agent 插件定义(如 3)。
|
|
323
323
|
*/
|
|
324
324
|
maxAgentDepth?: number;
|
|
325
|
+
/**
|
|
326
|
+
* 启用 tracing 的全局默认值(默认 true)
|
|
327
|
+
*
|
|
328
|
+
* 开启时 `agent.run()` / `agent.stream()` 返回的 `result.trace` /
|
|
329
|
+
* `chunk.traceEvent` 填充结构化调用明细(按轮次组织的 LLM 调用、tool 调用、
|
|
330
|
+
* sub-agent 嵌套调用事件,含 timing 与 token 用量)。
|
|
331
|
+
*
|
|
332
|
+
* 三层覆盖优先级:`AgentRunOptions.enableTracing` > agent 自身配置 >
|
|
333
|
+
* 此全局配置 > 默认 `true`。
|
|
334
|
+
*
|
|
335
|
+
* 业务方在生产主路径(高 QPS 端点)显式设 `false` 关闭以零开销运行:
|
|
336
|
+
*
|
|
337
|
+
* ```ts
|
|
338
|
+
* import type { FaapiConfig } from '@faapi/faapi';
|
|
339
|
+
* export default {
|
|
340
|
+
* agent: {
|
|
341
|
+
* enableTracing: false,
|
|
342
|
+
* llms: { openai: { provider: 'openai', apiKey: '...', models: { 'gpt-4o': {} } } },
|
|
343
|
+
* },
|
|
344
|
+
* } satisfies FaapiConfig;
|
|
345
|
+
* ```
|
|
346
|
+
*
|
|
347
|
+
* 详见 `@faapi/agent` 的 [trace](../../agent/src/trace.md) 文档。
|
|
348
|
+
*/
|
|
349
|
+
enableTracing?: boolean;
|
|
325
350
|
}
|
|
326
351
|
/**
|
|
327
352
|
* faapi 配置文件类型
|
|
@@ -582,17 +607,28 @@ interface WsContext {
|
|
|
582
607
|
type WsHandler = (ctx: WsContext) => WsEventHandlers | void;
|
|
583
608
|
|
|
584
609
|
/**
|
|
585
|
-
* 清理所有 Program
|
|
610
|
+
* 清理所有 Program 缓存 + tsconfig 解析缓存(watch 模式下文件变化时调用)
|
|
586
611
|
*
|
|
587
612
|
* 全量清理而非增量清理,理由:
|
|
588
613
|
* - 简单可靠,无状态一致性问题
|
|
589
614
|
* - 跨文件类型引用需要所有文件的 Program 同步更新
|
|
615
|
+
* - tsconfig 可能变化,需重新读取
|
|
590
616
|
* - dev 模式文件量有限,全量重建在百毫秒级
|
|
591
617
|
*/
|
|
592
618
|
declare function invalidateProgramCache(): void;
|
|
593
619
|
/**
|
|
594
620
|
* 为指定文件创建 TypeScript Program(带缓存)
|
|
595
621
|
*
|
|
622
|
+
* 从 filePath 向上查找最近的 tsconfig.json:
|
|
623
|
+
* - 找到:用 ts.parseJsonConfigFileContent 解析,取 module / moduleResolution
|
|
624
|
+
* 覆盖默认值,同时取 parsed.fileNames 作为 program 的 rootNames(让跨文件
|
|
625
|
+
* import 的源文件被加载进 program)
|
|
626
|
+
* - 找不到(如 os.tmpdir() 测试场景):回退到默认 NodeNext,rootNames 仅包含 filePath
|
|
627
|
+
*
|
|
628
|
+
* 加载全部相关文件保证 `resolveTypeReference` 的兜底遍历(找同名声明)能成功,
|
|
629
|
+
* 修复业务项目用 `moduleResolution: Bundler` + 无扩展名相对导入时跨文件
|
|
630
|
+
* `import type` 解析失败的问题。
|
|
631
|
+
*
|
|
596
632
|
* @param filePath 要分析的 .ts 文件绝对路径
|
|
597
633
|
*/
|
|
598
634
|
declare function createProgram(filePath: string): ts.Program;
|
|
@@ -967,9 +1003,9 @@ interface ToolPathMeta {
|
|
|
967
1003
|
* 返回 [AgentCore](../ast/extractAgentMetadata.md) 字段(name / description /
|
|
968
1004
|
* systemPrompt / tools / agents / model / maxTurns),**不含** `filePath` / `hasRun`。
|
|
969
1005
|
*
|
|
970
|
-
*
|
|
971
|
-
*
|
|
972
|
-
*
|
|
1006
|
+
* 仅查文件 registry(编译期 `faapi-agents.js` 产物来源)。**不 fallback 到
|
|
1007
|
+
* [skillRegistry](./skillRegistry.ts)**——skill 与 agent 职责正交不耦合,
|
|
1008
|
+
* skill 由业务方 plugin 内部使用,不参与 agent 查询链路。
|
|
973
1009
|
*
|
|
974
1010
|
* 用于 LLM-facing 场景(`agents` 参数注入、`asTool` 描述、
|
|
975
1011
|
* `resolveAgentTools` / `resolveSubAgents` 解析)。
|
|
@@ -986,11 +1022,10 @@ declare function getAgent(name: string): AgentCore | undefined;
|
|
|
986
1022
|
* 额外含 `filePath` / `hasRun`,供 `@faapi/agent` 子包 `loadAgentModule`
|
|
987
1023
|
* 加载 handler.js 执行自定义 `run` 函数。
|
|
988
1024
|
*
|
|
989
|
-
* **不 fallback 到 skillRegistry**——DB skill 无源文件,不走 `loadAgentModule`。
|
|
990
1025
|
* 调用方需先判断 `entry?.hasRun` 再决定是否加载 handler.js。
|
|
991
1026
|
*
|
|
992
1027
|
* @param name agent 名
|
|
993
|
-
* @returns `AgentMetadata` 或 `undefined
|
|
1028
|
+
* @returns `AgentMetadata` 或 `undefined`(未注册)
|
|
994
1029
|
*/
|
|
995
1030
|
declare function getAgentEntry(name: string): AgentMetadata | undefined;
|
|
996
1031
|
/**
|
|
@@ -1029,9 +1064,7 @@ interface AgentToolDescriptor {
|
|
|
1029
1064
|
*
|
|
1030
1065
|
* agent 必须显式声明用哪些 tool,显式优于隐式。
|
|
1031
1066
|
*
|
|
1032
|
-
*
|
|
1033
|
-
* skill 的 `tools` 字段同样会被解析。DB skill 引用的 tool 必须在 toolRegistry
|
|
1034
|
-
* 注册(文件型 tool 或未来 DB-driven tool)。
|
|
1067
|
+
* 通过 [getAgent](#getAgent) 查询文件型 agent,不 fallback 到 skillRegistry。
|
|
1035
1068
|
*
|
|
1036
1069
|
* `tools` 中未在 toolRegistry 找到的 tool 名静默跳过(tool 可选可用,不强制存在)。
|
|
1037
1070
|
*
|
|
@@ -1046,10 +1079,10 @@ declare function resolveAgentTools(name: string): ToolMetadata[];
|
|
|
1046
1079
|
* 解析 agent 可调用的子 agent 集合
|
|
1047
1080
|
*
|
|
1048
1081
|
* 读 `agent.agents` 字段([extractAgentMetadata](../ast/extractAgentMetadata.md)
|
|
1049
|
-
* 提取的 `config.agents`
|
|
1082
|
+
* 提取的 `config.agents` 字面量列表),按名查找已注册文件型 agent。
|
|
1050
1083
|
*
|
|
1051
|
-
*
|
|
1052
|
-
* 父 agent
|
|
1084
|
+
* 不 fallback 到 skillRegistry——skill 不参与 sub-agent 递归,
|
|
1085
|
+
* 父 agent 的 `agents` 列表只能引用文件型 agent 名。
|
|
1053
1086
|
*
|
|
1054
1087
|
* 返回 `AgentCore[]`(LLM-facing 字段,供 `@faapi/agent` 子包包装为
|
|
1055
1088
|
* `AgentToolDescriptor` 发给 LLM)。加载 sub-agent handler.js 执行 `run` 函数
|