@faapi/faapi 6.23.0 → 6.24.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.
@@ -60,13 +60,13 @@ interface ToolPathMeta {
60
60
  /**
61
61
  * Agent 的 LLM 可见核心字段
62
62
  *
63
- * 描述"agent 是什么"——LLM 真正需要消费的字段,**不含**代码本体加载细节
64
- * (filePath / hasRun)。文件型 agent 与 DB-driven skill 都实现此接口。
63
+ * 描述"agent 是什么"——LLM 真正需要消费的字段,**不含**声明文件定位信息
64
+ * (filePath)。文件型 agent 与 DB-driven skill 都实现此接口。
65
65
  *
66
66
  * - 文件型 agent:由 [AgentMetadata](./extractAgentMetadata.md) 继承扩展,
67
- * 额外含 `filePath` / `hasRun`(代码本体加载用)
67
+ * 额外含 `filePath`(声明文件定位用)
68
68
  * - DB-driven skill:业务方 plugin 从 DB 字段映射到本接口即可,无需填占位值
69
- * (skill 无源文件,不走 `loadAgentModule`,自然不读 filePath / hasRun)
69
+ * (skill 无源文件,自然不读 filePath)
70
70
  *
71
71
  * `@faapi/agent` 子包的 `Agent` 类、`agentRegistry` 查询入口、`asTool` 包装
72
72
  * 都消费 `AgentCore`,实现"agent 与 skill 走同一运行时链路"。
@@ -78,6 +78,16 @@ interface AgentCore {
78
78
  description?: string;
79
79
  /** 系统提示词(config 块字面量提取);文件型 agent 必填(构建期校验),DB skill 由业务方自治 */
80
80
  systemPrompt?: string;
81
+ /**
82
+ * 系统提示词文件路径(config 块字面量提取),相对产物 resources 目录
83
+ * (`<dist>/resources/`,即 `ctx.resourcesDir`),与 `systemPrompt` 互斥
84
+ * (都声明构建期抛错,二选一必填)
85
+ *
86
+ * 运行时每次 run 读文件内容作为 systemPrompt——dev 改 prompt 文件经 watcher
87
+ * 增量复制后立即生效,无需 reload;`deps.resourcesDir` 未注入或文件读取失败
88
+ * 时抛 `AgentError`(不静默降级)
89
+ */
90
+ systemPromptFile?: string;
81
91
  /** agent 显式声明可用的 tool 引用列表(config 块字面量提取),未声明时为 `undefined`;声明了但含无法静态求值的元素在构建期抛错 */
82
92
  tools?: string[];
83
93
  /** 可调用的其他 agent 名列表(config 块字面量提取),未声明时为 `undefined`;声明了但含无法静态求值的元素在构建期抛错 */
@@ -99,12 +109,13 @@ interface AgentCore {
99
109
  /**
100
110
  * Agent 完整元数据(文件型 agent)
101
111
  *
102
- * 继承 [AgentCore](./extractAgentMetadata.md) 的 LLM 字段,额外扩展**代码本体加载细节**:
103
- * - `filePath` — `loadAgentModule` 加载 `handler.js` 产物提取 `run` 函数用
104
- * - `hasRun` — 是否导出 `run` 函数(`Agent.executeSubAgent` 据此决定走自定义 run
105
- * 还是默认 reactLoop)
112
+ * 继承 [AgentCore](./extractAgentMetadata.md) 的 LLM 字段,额外扩展声明文件定位:
113
+ * - `filePath` — 声明文件源码相对路径(启动日志 / 清单可观测性用)
106
114
  *
107
- * DB-driven skill 不实现此接口(无源文件,无需加载),只实现 `AgentCore`。
115
+ * agent 统一为声明式执行(config + 默认 reactLoop)——自定义 `run` 导出已移除,
116
+ * 检测到 run 导出在提取阶段抛迁移错误(编排场景注册 tool)。
117
+ *
118
+ * DB-driven skill 不实现此接口(无源文件),只实现 `AgentCore`。
108
119
  *
109
120
  * 由 [extractAgentMetadata](./extractAgentMetadata.md) 产出,合并路径推导字段
110
121
  * (来自 [scanAgents](../agents/scanAgents.md) 的 `AgentManifest`)与 AST 提取字段
@@ -112,15 +123,13 @@ interface AgentCore {
112
123
  *
113
124
  * 字段来源:
114
125
  * - `name` — `@agent` JSDoc 覆盖值,或 `pathMeta.name`(目录推导)
115
- * - `filePath` / `hasRun` — 由 `pathMeta` 透传
126
+ * - `filePath` — 由 `pathMeta` 透传
116
127
  * - `description` — JSDoc 注释块自由文本(对 LLM 可见)
117
- * - `systemPrompt` / `tools` / `agents` / `model` / `maxTurns` / `inputDescription` — config 块字面量提取
128
+ * - `systemPrompt` / `systemPromptFile` / `tools` / `agents` / `model` / `maxTurns` / `inputDescription` — config 块字面量提取
118
129
  */
119
130
  interface AgentMetadata extends AgentCore {
120
- /** 源码相对路径(从 `pathMeta` 透传),`loadAgentModule` 据此加载 `handler.js` 提取 `run` */
131
+ /** 源码相对路径(从 `pathMeta` 透传)——声明文件定位与清单可观测性用 */
121
132
  filePath: string;
122
- /** 是否导出 `run` 函数(从 `pathMeta` 透传),`Agent.executeSubAgent` 据此选择自定义 run / 默认 reactLoop */
123
- hasRun: boolean;
124
133
  }
125
134
  /**
126
135
  * 路径推导的 agent 元数据(由 [scanAgents](../agents/scanAgents.ts) 计算)
@@ -133,8 +142,6 @@ interface AgentPathMeta {
133
142
  name: string;
134
143
  /** 源码相对路径(如 `src/agents/researcher/handler.ts`) */
135
144
  filePath: string;
136
- /** 是否导出 `run` 函数(scanAgents 正则检测) */
137
- hasRun: boolean;
138
145
  }
139
146
 
140
147
  /**
@@ -356,6 +363,8 @@ interface TaskWorkerOptions {
356
363
  /** signal 由执行器构造(abort/terminate 时触发),宿主只传 config 与 job 信息 */
357
364
  taskCtx: {
358
365
  config: unknown;
366
+ /** 产物 resources 目录绝对路径(纯字符串可结构化克隆,worker 内挂到 taskCtx) */
367
+ resourcesDir?: string;
359
368
  job: {
360
369
  id: string;
361
370
  name: string;
@@ -439,7 +448,7 @@ interface AgentRegistry {
439
448
  hydrate(agents: AgentMetadata[]): void;
440
449
  /** LLM 可见元数据(AgentCore) */
441
450
  getAgent(name: string): AgentCore | undefined;
442
- /** 完整元数据(含 filePath / hasRun,供加载 handler.js 执行 run) */
451
+ /** 完整元数据(含 filePath,声明文件定位) */
443
452
  getAgentEntry(name: string): AgentMetadata | undefined;
444
453
  /** 所有已注册 agent 的 LLM 可见元数据(副本) */
445
454
  listAgents(): AgentCore[];
@@ -602,7 +611,7 @@ interface TaskJob {
602
611
  * `TaskRegistriesView` 生成快照,worker wrapper 内重建只读视图。
603
612
  */
604
613
  interface TaskRegistriesSnapshot {
605
- /** agent 完整元数据(含 filePath/hasRun,非仅 LLM 可见字段) */
614
+ /** agent 完整元数据(含 filePath,非仅 LLM 可见字段) */
606
615
  agents: AgentMetadata[];
607
616
  tools: ToolMetadata[];
608
617
  skills: AgentCore[];
@@ -615,6 +624,14 @@ interface TaskContext {
615
624
  signal: AbortSignal;
616
625
  /** faapi.config.ts 全量配置(含自定义业务配置) */
617
626
  config: unknown;
627
+ /**
628
+ * 产物 resources 目录绝对路径(`<rootDir>/<dist>/resources`)
629
+ *
630
+ * 任务读静态文件(prompt 模板等)用:`fs.readFile(path.join(taskCtx.resourcesDir, 'x.md'))`。
631
+ * 进程内与隔离执行两条路径均注入(隔离为纯字符串,可结构化克隆);
632
+ * 直接构造 TaskContext 的测试/自定义执行器可不传。
633
+ */
634
+ resourcesDir?: string;
618
635
  job: {
619
636
  id: string;
620
637
  name: string;
@@ -625,7 +642,7 @@ interface TaskContext {
625
642
  *
626
643
  * 进程内执行为活引用;隔离执行为派发时刻的快照视图(worker 内重建)——
627
644
  * 执行中途的 reload/DB skill 变更不影响当次执行。
628
- * 任务内组装 agent 用 `registries.agent.getAgentEntry(name)`(含 filePath/hasRun)。
645
+ * 任务内组装 agent 用 `registries.agent.getAgentEntry(name)`(含 filePath)。
629
646
  */
630
647
  registries: TaskRegistriesView;
631
648
  /**
@@ -714,6 +731,11 @@ interface TaskQueueDeps {
714
731
  rootDir: string;
715
732
  /** faapi.config.ts 全量配置,透传给 run 的 TaskContext.config */
716
733
  config?: unknown;
734
+ /**
735
+ * 产物 resources 目录绝对路径——注入两条执行路径的 TaskContext.resourcesDir;
736
+ * 缺省不注入(直接构造队列的测试/嵌入场景)
737
+ */
738
+ resourcesDir?: string;
717
739
  /**
718
740
  * app 注册表只读视图(`createTaskRegistriesView`)——注入两条执行路径的
719
741
  * TaskContext.registries;缺省为空视图(直接构造队列的测试/嵌入场景)
package/dist/testing.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as FaapiContext, F as FaapiMiddleware, I as InjectorMap, R as RouteManifest, W as WsRouteManifest, C as CorsOptions, H as HelmetOptions } from './routeTypes-CJV5M90s.js';
1
+ import { a as FaapiContext, F as FaapiMiddleware, I as InjectorMap, R as RouteManifest, W as WsRouteManifest, C as CorsOptions, H as HelmetOptions } from './routeTypes-D1swYDVC.js';
2
2
  import { Server } from 'node:http';
3
3
  import { WebSocket } from 'ws';
4
4