@faapi/faapi 6.26.0 → 6.28.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 +82 -49
- package/dist/cli/index.js.map +1 -1
- package/dist/{contextTypes-gYf84EXF.d.ts → contextTypes-DhagvRH_.d.ts} +9 -25
- package/dist/index.d.ts +35 -28
- package/dist/index.js +124 -96
- package/dist/index.js.map +1 -1
- package/dist/{routeTypes-DlD6nnbT.d.ts → routeTypes-0rwuIws-.d.ts} +1 -1
- package/dist/testing.d.ts +3 -3
- package/dist/testing.js +59 -77
- package/dist/testing.js.map +1 -1
- package/dist/workerEntry.d.ts +1 -1
- package/dist/workerEntry.js +2 -1
- package/dist/workerEntry.js.map +1 -1
- package/package.json +1 -1
|
@@ -51,7 +51,7 @@ interface ToolMetadata extends ToolCore {
|
|
|
51
51
|
* 透传到 [ToolMetadata](./extractToolMetadata.ts) 输出,与 AST 提取字段合并。
|
|
52
52
|
*/
|
|
53
53
|
interface ToolPathMeta {
|
|
54
|
-
/** 路径推导的 tool 名(如 `
|
|
54
|
+
/** 路径推导的 tool 名(如 `weather_getWeather`) */
|
|
55
55
|
name: string;
|
|
56
56
|
/** 源码相对路径(如 `src/tools/weather/handler.ts`) */
|
|
57
57
|
filePath: string;
|
|
@@ -80,7 +80,7 @@ interface AgentCore {
|
|
|
80
80
|
systemPrompt?: string;
|
|
81
81
|
/**
|
|
82
82
|
* 系统提示词文件路径(config 块字面量提取),相对产物 resources 目录
|
|
83
|
-
* (`<dist>/resources
|
|
83
|
+
* (`<dist>/resources/`,运行时经免传参 `readResource` 读取),与 `systemPrompt` 互斥
|
|
84
84
|
* (都声明构建期抛错,二选一必填)
|
|
85
85
|
*
|
|
86
86
|
* 运行时每次 run 读文件内容作为 systemPrompt——dev 改 prompt 文件经 watcher
|
|
@@ -364,9 +364,8 @@ interface TaskWorkerOptions {
|
|
|
364
364
|
taskCtx: {
|
|
365
365
|
config: unknown;
|
|
366
366
|
/**
|
|
367
|
-
* 产物 resources
|
|
368
|
-
*
|
|
369
|
-
* taskCtx(业务方了解/拼接资源位置)
|
|
367
|
+
* 产物 resources 目录绝对路径(纯字符串可结构化克隆)——经 workerData
|
|
368
|
+
* 传给入口在任务模块求值前播种全局读取根(内部字段,不进业务 taskCtx)
|
|
370
369
|
*/
|
|
371
370
|
resourcesDir?: string;
|
|
372
371
|
job: {
|
|
@@ -433,7 +432,7 @@ declare function runTaskInWorker(options: TaskWorkerOptions): Promise<unknown>;
|
|
|
433
432
|
interface ToolRegistry {
|
|
434
433
|
/** 全量替换(tool 清单来自编译期产物,reload 时整体重新生成) */
|
|
435
434
|
hydrate(tools: ToolMetadata[]): void;
|
|
436
|
-
/** 按全名查找(如 `
|
|
435
|
+
/** 按全名查找(如 `weather_getWeather`) */
|
|
437
436
|
get(name: string): ToolMetadata | undefined;
|
|
438
437
|
/** 所有已注册 tool(副本) */
|
|
439
438
|
list(): ToolMetadata[];
|
|
@@ -628,14 +627,6 @@ interface TaskContext {
|
|
|
628
627
|
signal: AbortSignal;
|
|
629
628
|
/** faapi.config.ts 全量配置(含自定义业务配置) */
|
|
630
629
|
config: unknown;
|
|
631
|
-
/**
|
|
632
|
-
* 产物 resources 目录绝对路径(`<rootDir>/<dist>/resources`)
|
|
633
|
-
*
|
|
634
|
-
* 任务读静态文件(prompt 模板等)用:`fs.readFile(path.join(taskCtx.resourcesDir, 'x.md'))`。
|
|
635
|
-
* 进程内与隔离执行两条路径均注入(隔离为纯字符串,可结构化克隆);
|
|
636
|
-
* 直接构造 TaskContext 的测试/自定义执行器可不传。
|
|
637
|
-
*/
|
|
638
|
-
resourcesDir?: string;
|
|
639
630
|
job: {
|
|
640
631
|
id: string;
|
|
641
632
|
name: string;
|
|
@@ -736,8 +727,10 @@ interface TaskQueueDeps {
|
|
|
736
727
|
/** faapi.config.ts 全量配置,透传给 run 的 TaskContext.config */
|
|
737
728
|
config?: unknown;
|
|
738
729
|
/**
|
|
739
|
-
* 产物 resources
|
|
740
|
-
*
|
|
730
|
+
* 产物 resources 目录绝对路径——**内部字段**,仅作隔离 worker 读取根播种的
|
|
731
|
+
* 数据源(经 workerData 传入 workerEntry,不进业务可见的 TaskContext——
|
|
732
|
+
* 任务读资源统一走免传参 `readResource`);缺省不播种(直接构造队列的
|
|
733
|
+
* 测试/嵌入场景,readResource 未绑定即显式抛错)
|
|
741
734
|
*/
|
|
742
735
|
resourcesDir?: string;
|
|
743
736
|
/**
|
|
@@ -1051,15 +1044,6 @@ interface FaapiContext {
|
|
|
1051
1044
|
cookies: Record<string, string>;
|
|
1052
1045
|
/** 配置文件中的自定义业务配置(类型可通过 declare module '@faapi/faapi' 增强 FaapiContextConfig) */
|
|
1053
1046
|
config: FaapiContextConfig;
|
|
1054
|
-
/**
|
|
1055
|
-
* 运行时资源根目录绝对路径(<rootDir>/<dist>/resources)
|
|
1056
|
-
*
|
|
1057
|
-
* `src/resources/` 经 dev/build 复制进产物后的位置。数据字段——读取统一走
|
|
1058
|
-
* 免传参的 `readResource('prompts/foo.md')`(app 启动时绑定,见
|
|
1059
|
-
* src/utils/readResource.md),本字段供业务方了解/拼接资源位置。
|
|
1060
|
-
* HTTP/WS 请求链路恒有值;testing 直调(createTestContext)未传时为 undefined。
|
|
1061
|
-
*/
|
|
1062
|
-
resourcesDir?: string;
|
|
1063
1047
|
/**
|
|
1064
1048
|
* 设置响应状态码
|
|
1065
1049
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { A as AppRegistries, F as FaapiContext, T as TaskClient, L as LogConfig, a as TaskFailedHandler, b as TaskQueueDeps, c as TaskQueue, d as TaskDriver, e as TaskRegistry, f as TaskManifest, g as ToolMetadata, h as AgentCore, i as AgentMetadata, C as CreateLoggerOptions, j as Logger } from './contextTypes-
|
|
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 LogEntry, t as LogLevel, u as LogSink, S as SkillRegistry, v as SseEvent, w as SseOptions, x as SseWriter, y as TaskContext, z as TaskDriverJob, B as TaskDriverProcess, D as TaskDriverRecord, E as TaskFailedInfo, G as TaskJob, H as TaskJobStatus, I as TaskMetadata, J as TaskModule, K as TaskRegistriesSnapshot, M as TaskRegistriesView, N as ToolCore, O as ToolPathMeta, P as ToolRegistry, Q as createAppRegistries, R as createTaskRegistriesView, U as createTaskRegistry } from './contextTypes-
|
|
3
|
-
import { F as FaapiMiddleware, R as RouteManifest, C as CorsOptions, H as HelmetOptions, I as InjectorMap, W as WsRouteManifest } from './routeTypes-
|
|
4
|
-
export { a as Injector, b as RouteInfo, c as RouteInputSchema, d as RouteOutputSchema, e as RouteParamSchema, f as cors, h as helmet } from './routeTypes-
|
|
1
|
+
import { A as AppRegistries, F as FaapiContext, T as TaskClient, L as LogConfig, a as TaskFailedHandler, b as TaskQueueDeps, c as TaskQueue, d as TaskDriver, e as TaskRegistry, f as TaskManifest, g as ToolMetadata, h as AgentCore, i as AgentMetadata, C as CreateLoggerOptions, j as Logger } from './contextTypes-DhagvRH_.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 LogEntry, t as LogLevel, u as LogSink, S as SkillRegistry, v as SseEvent, w as SseOptions, x as SseWriter, y as TaskContext, z as TaskDriverJob, B as TaskDriverProcess, D as TaskDriverRecord, E as TaskFailedInfo, G as TaskJob, H as TaskJobStatus, I as TaskMetadata, J as TaskModule, K as TaskRegistriesSnapshot, M as TaskRegistriesView, N as ToolCore, O as ToolPathMeta, P as ToolRegistry, Q as createAppRegistries, R as createTaskRegistriesView, U as createTaskRegistry } from './contextTypes-DhagvRH_.js';
|
|
3
|
+
import { F as FaapiMiddleware, R as RouteManifest, C as CorsOptions, H as HelmetOptions, I as InjectorMap, W as WsRouteManifest } from './routeTypes-0rwuIws-.js';
|
|
4
|
+
export { a as Injector, b as RouteInfo, c as RouteInputSchema, d as RouteOutputSchema, e as RouteParamSchema, f as cors, h as helmet } from './routeTypes-0rwuIws-.js';
|
|
5
5
|
import * as node_http from 'node:http';
|
|
6
6
|
import { Server, IncomingMessage, ServerResponse } from 'node:http';
|
|
7
7
|
import { Socket } from 'node:net';
|
|
@@ -50,14 +50,6 @@ type UpgradeHandler = (req: IncomingMessage, socket: Socket, head: Buffer) => vo
|
|
|
50
50
|
interface PluginContext {
|
|
51
51
|
/** 项目根目录 */
|
|
52
52
|
rootDir: string;
|
|
53
|
-
/**
|
|
54
|
-
* 产物 resources 目录绝对路径(`<rootDir>/<dist>/resources`)
|
|
55
|
-
*
|
|
56
|
-
* `src/resources/` 经 dev/build 复制进产物后的位置——插件 setup 时读静态
|
|
57
|
-
* 资源用;`@faapi/agent` 插件据此注入 AgentDeps(agent config 的
|
|
58
|
-
* systemPromptFile 相对此目录解析)。
|
|
59
|
-
*/
|
|
60
|
-
resourcesDir: string;
|
|
61
53
|
/** app 级注册表(tool/agent/skill/agentHandle 实例,随 app 生命周期) */
|
|
62
54
|
registries: AppRegistries;
|
|
63
55
|
/** 当前路由清单(setup 时的快照,reloadRoutes 后不会更新;需最新路由用 getRoutes()) */
|
|
@@ -261,13 +253,6 @@ interface TaskConfig {
|
|
|
261
253
|
interface LifecycleContext {
|
|
262
254
|
/** 项目根目录 */
|
|
263
255
|
rootDir: string;
|
|
264
|
-
/**
|
|
265
|
-
* 运行时资源根目录绝对路径(<rootDir>/<dist>/resources)
|
|
266
|
-
*
|
|
267
|
-
* `src/resources/` 经 dev/build 复制进产物后的位置,onReady 中预加载
|
|
268
|
-
* prompt 模板等静态文件时定位用(`path.join(resourcesDir, 'prompts/foo.md')`)。
|
|
269
|
-
*/
|
|
270
|
-
resourcesDir: string;
|
|
271
256
|
/** 当前路由清单 */
|
|
272
257
|
routes: RouteManifest;
|
|
273
258
|
/** 服务器实例(onBoot 钩子触发时已创建但未监听,`listening === false`) */
|
|
@@ -860,13 +845,6 @@ interface WsContext {
|
|
|
860
845
|
headers: Headers;
|
|
861
846
|
/** 业务配置(来自 faapi.config.ts) */
|
|
862
847
|
config: Record<string, unknown>;
|
|
863
|
-
/**
|
|
864
|
-
* 运行时资源根目录绝对路径(<rootDir>/<dist>/resources)
|
|
865
|
-
*
|
|
866
|
-
* 与 HTTP FaapiContext 同源(握手 ctx 是 FaapiContext 的结构子集),handler
|
|
867
|
-
* 的 WS 回调里读静态文件用。testing 直调未传时为 undefined。
|
|
868
|
-
*/
|
|
869
|
-
resourcesDir?: string;
|
|
870
848
|
/** 中间件塞入的用户信息(鉴权等) */
|
|
871
849
|
user?: unknown;
|
|
872
850
|
/** 允许通过 declare module 扩展 */
|
|
@@ -1370,11 +1348,40 @@ declare function resolveSubAgents(name: string): AgentCore[];
|
|
|
1370
1348
|
*
|
|
1371
1349
|
* 框架路径(`@faapi/agent` 插件 / 请求注入)从 app 实例查找。
|
|
1372
1350
|
*
|
|
1373
|
-
* @param tool 全名(如 `
|
|
1351
|
+
* @param tool 全名(如 `weather_getWeather`)
|
|
1374
1352
|
* @returns `ToolMetadata` 或 `undefined`(未注册)
|
|
1375
1353
|
*/
|
|
1376
1354
|
declare function getTool(name: string): ToolMetadata | undefined;
|
|
1377
1355
|
|
|
1356
|
+
/**
|
|
1357
|
+
* sub-agent 派发工具名生成(唯一入口)
|
|
1358
|
+
*
|
|
1359
|
+
* agent-as-tool 把 sub-agent 包装成 tool 发给 LLM,`function.name` 受 OpenAI 兼容协议
|
|
1360
|
+
* 硬约束 `^[a-zA-Z0-9_-]+$`——DeepSeek / OpenAI 等强校验上游对非法字符整单 400。
|
|
1361
|
+
* 历史上派发名是 `agent.<agentName>`(点号前缀 + 嵌套 agent 名的点号分隔),在强校验
|
|
1362
|
+
* 上游完全不可用(业务方反馈 TODO-faapi-gaps #1)。
|
|
1363
|
+
*
|
|
1364
|
+
* 命名规则:`agent-` 前缀 + agent 名直拼。agent 名的合法性由上游保证——文件型 agent
|
|
1365
|
+
* 在 scanAgents 目录段校验(段内 `[a-zA-Z0-9-]`,`_` 为 `/` 规范化后的嵌套分隔符)、
|
|
1366
|
+
* `@agent` 覆盖名在 extractAgentMetadata 校验(整体 `^[a-zA-Z0-9_-]+$`);本模块对组合
|
|
1367
|
+
* 结果做最后一道运行时闸门(程序化 hydrate 的 agent 名不经构建期扫描),违例显式抛错
|
|
1368
|
+
* ——不静默净化(掩盖配置错误),不降级放行(强校验上游 400)。
|
|
1369
|
+
*
|
|
1370
|
+
* 详见 [subAgentToolName.md](./subAgentToolName.md)。
|
|
1371
|
+
*/
|
|
1372
|
+
/** OpenAI 兼容协议对 LLM 工具名(function.name)的字符集约束 */
|
|
1373
|
+
declare const LLM_TOOL_NAME_PATTERN: RegExp;
|
|
1374
|
+
/** sub-agent 派发工具名前缀(旧版 `agent.` 点号前缀违反上述字符集,已废弃) */
|
|
1375
|
+
declare const SUB_AGENT_TOOL_PREFIX = "agent-";
|
|
1376
|
+
/**
|
|
1377
|
+
* 生成 sub-agent 派发工具名:`agent-<agentName>`
|
|
1378
|
+
*
|
|
1379
|
+
* @param agentName agent 注册名(scanAgents 目录推导或 `@agent` 覆盖名)
|
|
1380
|
+
* @returns 满足 {@link LLM_TOOL_NAME_PATTERN} 的派发工具名
|
|
1381
|
+
* @throws agent 名含工具名字符集之外的字符时抛错(含原名与改名指引)
|
|
1382
|
+
*/
|
|
1383
|
+
declare function subAgentToolName(agentName: string): string;
|
|
1384
|
+
|
|
1378
1385
|
/**
|
|
1379
1386
|
* skill 注册表全局访问器(默认实例便捷入口)
|
|
1380
1387
|
*
|
|
@@ -1765,4 +1772,4 @@ type ProdApp = AppBase;
|
|
|
1765
1772
|
*/
|
|
1766
1773
|
declare function createProdApp(options?: CreateAppOptions): Promise<ProdApp>;
|
|
1767
1774
|
|
|
1768
|
-
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, readResource, registerAgentHandleFactory, removeSkill, resolveAgentTools, resolveSubAgents, resolveTypeNode, scanTasks, upsertSkill };
|
|
1775
|
+
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, LLM_TOOL_NAME_PATTERN, 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, SUB_AGENT_TOOL_PREFIX, 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, readResource, registerAgentHandleFactory, removeSkill, resolveAgentTools, resolveSubAgents, resolveTypeNode, scanTasks, subAgentToolName, upsertSkill };
|