@faapi/faapi 6.29.0 → 6.31.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 +113 -3
- package/dist/cli/index.js.map +1 -1
- package/dist/{contextTypes-DhagvRH_.d.ts → contextTypes-BKQsSVMv.d.ts} +10 -1
- package/dist/index.d.ts +48 -31
- package/dist/index.js +119 -9
- package/dist/index.js.map +1 -1
- package/dist/{routeTypes-0rwuIws-.d.ts → routeTypes-Cc0P3CcU.d.ts} +1 -1
- package/dist/testing.d.ts +2 -2
- package/dist/workerEntry.d.ts +1 -1
- package/package.json +1 -1
|
@@ -130,6 +130,15 @@ interface AgentCore {
|
|
|
130
130
|
interface AgentMetadata extends AgentCore {
|
|
131
131
|
/** 源码相对路径(从 `pathMeta` 透传)——声明文件定位与清单可观测性用 */
|
|
132
132
|
filePath: string;
|
|
133
|
+
/**
|
|
134
|
+
* 派发入参 schema 声明(handler.ts 顶层 `interface Input` / `type Input` 检测)
|
|
135
|
+
*
|
|
136
|
+
* 声明时为 `'Input'`——[generateAgentArtifacts](../cli/generateAgentArtifacts.md)
|
|
137
|
+
* 据此生成 agent 的 zod.js,`@faapi/agent` 派发该 agent 时用富 JSON Schema 替代
|
|
138
|
+
* 默认单字段 `input` 交接单并在执行前校验;未声明为 `undefined`,派发行为不变
|
|
139
|
+
* (完全向后兼容)。DB-driven skill 无源文件,恒为 `undefined`。
|
|
140
|
+
*/
|
|
141
|
+
inputTypeName?: string;
|
|
133
142
|
}
|
|
134
143
|
/**
|
|
135
144
|
* 路径推导的 agent 元数据(由 [scanAgents](../agents/scanAgents.ts) 计算)
|
|
@@ -1159,4 +1168,4 @@ interface FaapiContext {
|
|
|
1159
1168
|
deleteCookie(name: string): void;
|
|
1160
1169
|
}
|
|
1161
1170
|
|
|
1162
|
-
export { type AppRegistries as A, type TaskDriverProcess as B, type CreateLoggerOptions as C, type TaskDriverRecord as D, type TaskFailedInfo as E, type FaapiContext as F, type TaskJob as G, type TaskJobStatus as H, type TaskMetadata as I, type TaskModule as J, type TaskRegistriesSnapshot as K, type LogConfig as L, type TaskRegistriesView as M, type ToolCore as N, type ToolPathMeta as O, type ToolRegistry as P, createAppRegistries as Q, createTaskRegistriesView as R, type SkillRegistry as S, type TaskClient as T, createTaskRegistry as U, type TaskFailedHandler as a, type TaskQueueDeps as b, type TaskQueue as c, type TaskDriver as d, type TaskRegistry as e, type TaskManifest as f, type
|
|
1171
|
+
export { type AppRegistries as A, type TaskDriverProcess as B, type CreateLoggerOptions as C, type TaskDriverRecord as D, type TaskFailedInfo as E, type FaapiContext as F, type TaskJob as G, type TaskJobStatus as H, type TaskMetadata as I, type TaskModule as J, type TaskRegistriesSnapshot as K, type LogConfig as L, type TaskRegistriesView as M, type ToolCore as N, type ToolPathMeta as O, type ToolRegistry as P, createAppRegistries as Q, createTaskRegistriesView as R, type SkillRegistry as S, type TaskClient as T, createTaskRegistry as U, type TaskFailedHandler as a, type TaskQueueDeps as b, type TaskQueue as c, type TaskDriver as d, type TaskRegistry as e, type TaskManifest as f, type AgentCore as g, type AgentMetadata as h, type ToolMetadata as i, type Logger as j, type AgentHandleFactory as k, type AgentHandleStore as l, type AgentPathMeta as m, type AgentRegistry as n, type AgentToolDescriptor as o, type FaapiContextConfig as p, type FaapiTaskMeta as q, type FailOptions as r, type LogEntry as s, type LogLevel as t, type LogSink as u, type SseEvent as v, type SseOptions as w, type SseWriter as x, type TaskContext as y, type TaskDriverJob as z };
|
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
|
|
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 AgentCore, h as AgentMetadata, i as ToolMetadata, C as CreateLoggerOptions, j as Logger } from './contextTypes-BKQsSVMv.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-BKQsSVMv.js';
|
|
3
|
+
import { F as FaapiMiddleware, R as RouteManifest, C as CorsOptions, H as HelmetOptions, I as InjectorMap, W as WsRouteManifest } from './routeTypes-Cc0P3CcU.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-Cc0P3CcU.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';
|
|
@@ -480,15 +480,6 @@ interface AgentConfig {
|
|
|
480
480
|
* 详见 `@faapi/agent` 的 [trace](../../agent/src/trace.md) 文档。
|
|
481
481
|
*/
|
|
482
482
|
enableTracing?: boolean;
|
|
483
|
-
/**
|
|
484
|
-
* 执行守卫(authHooks,见 @faapi/agent 的 authHooks 文档)
|
|
485
|
-
*
|
|
486
|
-
* 每次 tool / sub-agent 执行前调用(`agent.x` 名称为 sub-agent 递归)。
|
|
487
|
-
* 三种返回:`void` 放行;`{ error }` 拒绝(不执行,error 回传 LLM 调整策略);
|
|
488
|
-
* `{ args }` 改写后放行(多租户场景强制注入可信值,不信 LLM 传入的标识参数)。
|
|
489
|
-
*
|
|
490
|
-
* 典型用法:中间件解析 `ctx.workspace` 后在此校验/强制改写 `args.workspaceId`。
|
|
491
|
-
*/
|
|
492
483
|
/**
|
|
493
484
|
* 发送给 LLM 的历史 token 预算(近似估算,未设置 = 不裁剪)
|
|
494
485
|
*
|
|
@@ -498,7 +489,20 @@ interface AgentConfig {
|
|
|
498
489
|
* reactLoop 文档历史裁剪章节。
|
|
499
490
|
*/
|
|
500
491
|
maxHistoryTokens?: number;
|
|
501
|
-
|
|
492
|
+
/**
|
|
493
|
+
* 执行守卫(authHooks,见 @faapi/agent 的 authHooks 文档)
|
|
494
|
+
*
|
|
495
|
+
* 每次 tool / sub-agent 执行前调用(`agent-x` 派发名称为 sub-agent 递归)。
|
|
496
|
+
* 三种返回:`void` 放行;`{ error }` 拒绝(不执行,error 回传 LLM 调整策略);
|
|
497
|
+
* `{ args }` 改写后放行(多租户场景强制注入可信值,不信 LLM 传入的标识参数)。
|
|
498
|
+
*
|
|
499
|
+
* ctx 为请求上下文透传(`Partial<FaapiContext>`,框架零读取):HTTP 请求是完整
|
|
500
|
+
* ctx,任务内组装 Agent 时业务方显式传窄对象(如鉴权硬闸需要的
|
|
501
|
+
* `{ currentUserId }`),编程式直调为 undefined。
|
|
502
|
+
*
|
|
503
|
+
* 典型用法:中间件解析 `ctx.workspace` 后在此校验/强制改写 `args.workspaceId`。
|
|
504
|
+
*/
|
|
505
|
+
beforeToolCall?: (name: string, args: Record<string, unknown>, ctx: Partial<FaapiContext> | undefined) => void | {
|
|
502
506
|
error: string;
|
|
503
507
|
} | {
|
|
504
508
|
args: Record<string, unknown>;
|
|
@@ -507,7 +511,7 @@ interface AgentConfig {
|
|
|
507
511
|
* 审计钩子(authHooks):tool / sub-agent 成功返回后调用,返回值忽略。
|
|
508
512
|
* 用于日志/审计/计量;异常路径不调用。
|
|
509
513
|
*/
|
|
510
|
-
afterToolCall?: (name: string, args: Record<string, unknown>, result: unknown, ctx: FaapiContext | undefined) => void;
|
|
514
|
+
afterToolCall?: (name: string, args: Record<string, unknown>, result: unknown, ctx: Partial<FaapiContext> | undefined) => void;
|
|
511
515
|
/**
|
|
512
516
|
* 可见性过滤(authHooks):LLM 可见 tools 清单组装完成后调用,
|
|
513
517
|
* 返回过滤后的数组(含 agent-as-tool 项)。每次 agent.run / stream 生效——
|
|
@@ -523,7 +527,7 @@ interface AgentConfig {
|
|
|
523
527
|
description?: string;
|
|
524
528
|
parameters?: Record<string, unknown>;
|
|
525
529
|
};
|
|
526
|
-
}>, ctx: FaapiContext | undefined) => Array<{
|
|
530
|
+
}>, ctx: Partial<FaapiContext> | undefined) => Array<{
|
|
527
531
|
type: 'function';
|
|
528
532
|
function: {
|
|
529
533
|
name: string;
|
|
@@ -1295,31 +1299,44 @@ interface ToolSchemaModule {
|
|
|
1295
1299
|
* 计算 tool 的 zod.js 绝对路径(纯路径计算,无 fs 访问)
|
|
1296
1300
|
*
|
|
1297
1301
|
* 与 [loadToolSchema](./loadToolSchema.ts) 内部使用的路径逻辑同源(共享 `getDist()`),
|
|
1302
|
+
/**
|
|
1303
|
+
* zod.js 定位的最小来源结构——`ToolMetadata` 与 `AgentMetadata`(派发入参 schema
|
|
1304
|
+
* 声明场景)均满足,加载器无需感知来源差异
|
|
1305
|
+
*/
|
|
1306
|
+
interface SchemaSourceRef {
|
|
1307
|
+
/** 源码/产物相对路径(与 zod.js 同级,推导 zod.js 路径用) */
|
|
1308
|
+
filePath: string;
|
|
1309
|
+
/** schema 类型名(`undefined` = 无 schema 声明) */
|
|
1310
|
+
inputTypeName?: string;
|
|
1311
|
+
}
|
|
1312
|
+
/**
|
|
1313
|
+
* 计算 zod.js 的绝对路径(纯路径计算,无 fs 访问)
|
|
1314
|
+
*
|
|
1315
|
+
* 与 [loadToolSchema](./loadToolSchema.ts) 内部使用的路径逻辑同源(共享 `getDist()`),
|
|
1298
1316
|
* 供 `@faapi/agent` 的跨请求 schema 缓存用作缓存键 + mtime 校验目标。
|
|
1299
1317
|
*
|
|
1300
|
-
* @param
|
|
1301
|
-
* @param rootDir 项目根目录(`
|
|
1318
|
+
* @param ref schema 来源元数据(tool / agent 均可,含 `filePath`)
|
|
1319
|
+
* @param rootDir 项目根目录(`ref.filePath` 是相对路径时拼接)
|
|
1302
1320
|
*/
|
|
1303
|
-
declare function getToolSchemaPath(
|
|
1321
|
+
declare function getToolSchemaPath(ref: SchemaSourceRef, rootDir?: string): string;
|
|
1304
1322
|
/**
|
|
1305
|
-
* 动态加载
|
|
1323
|
+
* 动态加载 zod.js schema 模块(tool input 与 agent 派发入参共用)
|
|
1306
1324
|
*
|
|
1307
1325
|
* 与 [loadToolModule](./loadToolModule.md) 对称——一个加载 handler.js(tool 函数),
|
|
1308
|
-
* 一个加载 zod.js(tool
|
|
1326
|
+
* 一个加载 zod.js(schema 模块)。tool 的 zod.js 与 handler.js 同级;agent 声明
|
|
1327
|
+
* `Input` 时同样生成同级 zod.js(见 generateAgentArtifacts),同一加载器服务两类来源。
|
|
1309
1328
|
*
|
|
1310
1329
|
* 行为:
|
|
1311
|
-
* - `
|
|
1312
|
-
* - zod.js 文件不存在 → 返回 `undefined`(schema
|
|
1330
|
+
* - `ref.inputTypeName` 为 `undefined` → 返回 `undefined`(无 schema 声明)
|
|
1331
|
+
* - zod.js 文件不存在 → 返回 `undefined`(schema 缺失,调用方按各自语义处理——
|
|
1332
|
+
* tool 用自由 schema `{ type: 'object' }`;agent 派发入参在声明了 `inputTypeName`
|
|
1333
|
+
* 时视为产物异常,由 `@faapi/agent` 侧显式抛错)
|
|
1313
1334
|
* - import 失败 / 导出名不匹配 → 返回 `undefined`
|
|
1314
1335
|
*
|
|
1315
|
-
*
|
|
1316
|
-
*
|
|
1317
|
-
* LLM 自由传参,handler 内部自行处理参数合法性。
|
|
1318
|
-
*
|
|
1319
|
-
* @param tool tool 元数据(含 `filePath` + `inputTypeName`)
|
|
1320
|
-
* @param rootDir 项目根目录(用于计算 zod.js 绝对路径,`tool.filePath` 是相对路径时拼接)
|
|
1336
|
+
* @param ref schema 来源元数据(tool / agent 均可,含 `filePath` + `inputTypeName`)
|
|
1337
|
+
* @param rootDir 项目根目录(用于计算 zod.js 绝对路径,`ref.filePath` 是相对路径时拼接)
|
|
1321
1338
|
*/
|
|
1322
|
-
declare function loadToolSchema(
|
|
1339
|
+
declare function loadToolSchema(ref: SchemaSourceRef, rootDir?: string): Promise<ToolSchemaModule | undefined>;
|
|
1323
1340
|
|
|
1324
1341
|
/**
|
|
1325
1342
|
* 按名查找单个 agent 的 LLM 可见元数据(默认实例)
|
|
@@ -1764,4 +1781,4 @@ type ProdApp = AppBase;
|
|
|
1764
1781
|
*/
|
|
1765
1782
|
declare function createProdApp(options?: CreateAppOptions): Promise<ProdApp>;
|
|
1766
1783
|
|
|
1767
|
-
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 };
|
|
1784
|
+
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, type SchemaSourceRef, 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 };
|
package/dist/index.js
CHANGED
|
@@ -2864,6 +2864,34 @@ var CONCURRENCY_RE = new RegExp(`(?:^|\\n)\\s*concurrency:\\s*${NUM_LITERAL}`);
|
|
|
2864
2864
|
var RETRIES_RE = new RegExp(`(?:^|\\n)\\s*retries:\\s*${NUM_LITERAL}`);
|
|
2865
2865
|
var TIMEOUT_MS_RE = new RegExp(`(?:^|\\n)\\s*timeoutMs:\\s*${NUM_LITERAL}`);
|
|
2866
2866
|
var GRACE_MS_RE = new RegExp(`(?:^|\\n)\\s*graceMs:\\s*${NUM_LITERAL}`);
|
|
2867
|
+
var NUMERIC_META_FIELDS = ["concurrency", "retries", "timeoutMs", "graceMs"];
|
|
2868
|
+
var STRING_META_FIELDS = ["cron"];
|
|
2869
|
+
var ALL_META_FIELDS = [...NUMERIC_META_FIELDS, ...STRING_META_FIELDS];
|
|
2870
|
+
function detectIgnoredMetaFields(source, strictHit) {
|
|
2871
|
+
const declared = /* @__PURE__ */ new Set();
|
|
2872
|
+
for (const line of source.split("\n")) {
|
|
2873
|
+
const trimmed = line.trim();
|
|
2874
|
+
if (trimmed.startsWith("//")) continue;
|
|
2875
|
+
for (const field of ALL_META_FIELDS) {
|
|
2876
|
+
if (new RegExp(`\\b${field}\\s*:`).test(trimmed)) declared.add(field);
|
|
2877
|
+
}
|
|
2878
|
+
}
|
|
2879
|
+
return ALL_META_FIELDS.filter((field) => declared.has(field) && !strictHit[field]);
|
|
2880
|
+
}
|
|
2881
|
+
function warnIgnoredMetaFields(name, fields) {
|
|
2882
|
+
for (const field of fields) {
|
|
2883
|
+
if (STRING_META_FIELDS.includes(field)) {
|
|
2884
|
+
console.warn(
|
|
2885
|
+
`[faapi] Task "${name}" declares "${field}" but its value is not a string literal \u2014 the declaration was ignored and the task will not be cron-scheduled. Meta values are extracted from source code without importing it, so only literal values are recognized: use a quoted literal (cron: '0 3 * * *'), not an expression or a dynamic value.`
|
|
2886
|
+
);
|
|
2887
|
+
} else {
|
|
2888
|
+
const consequence = field === "timeoutMs" ? " and the task will run in-process with no timeout" : "";
|
|
2889
|
+
console.warn(
|
|
2890
|
+
`[faapi] Task "${name}" declares "${field}" but its value is not a numeric literal \u2014 the declaration was ignored${consequence}. Meta values are extracted from source code without importing it, so only literal values are recognized (underscores allowed, e.g. 1_800_000); expressions like 30 * 60_000 or dynamic values are not supported.`
|
|
2891
|
+
);
|
|
2892
|
+
}
|
|
2893
|
+
}
|
|
2894
|
+
}
|
|
2867
2895
|
function parseNumericLiteral(raw) {
|
|
2868
2896
|
return Number(raw.replace(/_/g, ""));
|
|
2869
2897
|
}
|
|
@@ -2925,6 +2953,14 @@ async function scanTasks(rootDir, patterns) {
|
|
|
2925
2953
|
manifest.timeoutMs = value;
|
|
2926
2954
|
}
|
|
2927
2955
|
if (graceMs !== void 0) manifest.graceMs = parseNumericLiteral(graceMs);
|
|
2956
|
+
const strictHit = {
|
|
2957
|
+
cron: cron !== void 0,
|
|
2958
|
+
concurrency: concurrency !== void 0,
|
|
2959
|
+
retries: retries !== void 0,
|
|
2960
|
+
timeoutMs: timeoutMs !== void 0,
|
|
2961
|
+
graceMs: graceMs !== void 0
|
|
2962
|
+
};
|
|
2963
|
+
warnIgnoredMetaFields(name, detectIgnoredMetaFields(source, strictHit));
|
|
2928
2964
|
tasks.push(manifest);
|
|
2929
2965
|
}
|
|
2930
2966
|
return tasks.sort((a, b) => a.name.localeCompare(b.name));
|
|
@@ -3890,18 +3926,18 @@ function getDist() {
|
|
|
3890
3926
|
}
|
|
3891
3927
|
return process.env.FAAPI_DIST ?? "dist";
|
|
3892
3928
|
}
|
|
3893
|
-
function getToolSchemaPath(
|
|
3929
|
+
function getToolSchemaPath(ref, rootDir) {
|
|
3894
3930
|
const dist = getDist();
|
|
3895
|
-
return getRuntimeSchemaPath(
|
|
3931
|
+
return getRuntimeSchemaPath(ref.filePath, dist, rootDir ?? process.cwd());
|
|
3896
3932
|
}
|
|
3897
|
-
async function loadToolSchema(
|
|
3898
|
-
if (!
|
|
3899
|
-
const schemaName = `${
|
|
3900
|
-
const zodPath = getToolSchemaPath(
|
|
3933
|
+
async function loadToolSchema(ref, rootDir) {
|
|
3934
|
+
if (!ref.inputTypeName) return void 0;
|
|
3935
|
+
const schemaName = `${ref.inputTypeName}Schema`;
|
|
3936
|
+
const zodPath = getToolSchemaPath(ref, rootDir);
|
|
3901
3937
|
if (!existsSync3(zodPath)) return void 0;
|
|
3902
3938
|
try {
|
|
3903
3939
|
const mod = await importWithCacheBust(zodPath, isDevOnDemandEnabled());
|
|
3904
|
-
const schema = mod[`${
|
|
3940
|
+
const schema = mod[`${ref.inputTypeName}Schema`];
|
|
3905
3941
|
if (!schema) return void 0;
|
|
3906
3942
|
return { schema, schemaName };
|
|
3907
3943
|
} catch {
|
|
@@ -6866,9 +6902,20 @@ function extractAgentMetadata(program, filePath, pathMeta) {
|
|
|
6866
6902
|
agents,
|
|
6867
6903
|
model,
|
|
6868
6904
|
maxTurns,
|
|
6869
|
-
inputDescription
|
|
6905
|
+
inputDescription,
|
|
6906
|
+
inputTypeName: findInputDeclaration(sourceFile) ? "Input" : void 0
|
|
6870
6907
|
};
|
|
6871
6908
|
}
|
|
6909
|
+
function findInputDeclaration(sourceFile) {
|
|
6910
|
+
let found = false;
|
|
6911
|
+
ts11.forEachChild(sourceFile, (node) => {
|
|
6912
|
+
if (found) return;
|
|
6913
|
+
if ((ts11.isInterfaceDeclaration(node) || ts11.isTypeAliasDeclaration(node)) && node.name.text === "Input") {
|
|
6914
|
+
found = true;
|
|
6915
|
+
}
|
|
6916
|
+
});
|
|
6917
|
+
return found;
|
|
6918
|
+
}
|
|
6872
6919
|
function findRunExportOwner(sourceFile) {
|
|
6873
6920
|
let result = null;
|
|
6874
6921
|
ts11.forEachChild(sourceFile, (node) => {
|
|
@@ -7075,6 +7122,9 @@ function extractStringArrayValue(expr) {
|
|
|
7075
7122
|
// src/cli/generateAgentArtifacts.ts
|
|
7076
7123
|
init_createProgram();
|
|
7077
7124
|
init_atomicWrite();
|
|
7125
|
+
init_extractHandlerTypes();
|
|
7126
|
+
init_generateZodSchema();
|
|
7127
|
+
init_generateZodArtifacts();
|
|
7078
7128
|
var AGENTS_FILE = "faapi-agents.js";
|
|
7079
7129
|
function serializeAgents(agents, dist = "dist") {
|
|
7080
7130
|
return agents.map((a) => ({
|
|
@@ -7087,6 +7137,7 @@ function serializeAgents(agents, dist = "dist") {
|
|
|
7087
7137
|
model: a.model,
|
|
7088
7138
|
maxTurns: a.maxTurns,
|
|
7089
7139
|
inputDescription: a.inputDescription,
|
|
7140
|
+
inputTypeName: a.inputTypeName,
|
|
7090
7141
|
filePath: toProdFilePath(a.filePath, dist)
|
|
7091
7142
|
}));
|
|
7092
7143
|
}
|
|
@@ -7107,7 +7158,8 @@ function hydrateAgents(manifest) {
|
|
|
7107
7158
|
agents: a.agents ?? void 0,
|
|
7108
7159
|
model: a.model ?? void 0,
|
|
7109
7160
|
maxTurns: a.maxTurns ?? void 0,
|
|
7110
|
-
inputDescription: a.inputDescription ?? void 0
|
|
7161
|
+
inputDescription: a.inputDescription ?? void 0,
|
|
7162
|
+
inputTypeName: a.inputTypeName ?? void 0
|
|
7111
7163
|
}));
|
|
7112
7164
|
}
|
|
7113
7165
|
function validateAgentList(metadata) {
|
|
@@ -7153,8 +7205,66 @@ async function generateAgentArtifacts(agents, rootDir, dist) {
|
|
|
7153
7205
|
const serialized = serializeAgents(metadata, dist);
|
|
7154
7206
|
const agentsPath = path24.resolve(rootDir, dist, AGENTS_FILE);
|
|
7155
7207
|
await writeAgentsModule(serialized, agentsPath);
|
|
7208
|
+
await generateAgentZodArtifacts(metadata, programByFile, rootDir, dist);
|
|
7156
7209
|
return metadata;
|
|
7157
7210
|
}
|
|
7211
|
+
async function generateAgentZodArtifacts(metadata, programByFile, rootDir, dist) {
|
|
7212
|
+
const declared = metadata.filter((a) => a.inputTypeName);
|
|
7213
|
+
if (declared.length === 0) return;
|
|
7214
|
+
const resolversByFile = /* @__PURE__ */ new Map();
|
|
7215
|
+
const sources = [];
|
|
7216
|
+
for (const agent of declared) {
|
|
7217
|
+
const absPath = path24.resolve(rootDir, agent.filePath);
|
|
7218
|
+
const program = programByFile.get(absPath);
|
|
7219
|
+
if (!program) {
|
|
7220
|
+
throw new Error(
|
|
7221
|
+
`agent "${agent.name}" \u6E90\u6587\u4EF6\u4E0D\u5728 Program \u4E2D: ${agent.filePath}\u2014\u2014\u65E0\u6CD5\u751F\u6210\u5165\u53C2 schema`
|
|
7222
|
+
);
|
|
7223
|
+
}
|
|
7224
|
+
if (!resolversByFile.has(absPath)) {
|
|
7225
|
+
resolversByFile.set(absPath, createLazyTypeResolver(program, absPath));
|
|
7226
|
+
}
|
|
7227
|
+
const typeInfo = extractTypeInfo(program, absPath, agent.inputTypeName);
|
|
7228
|
+
sources.push({
|
|
7229
|
+
name: agent.name,
|
|
7230
|
+
filePath: absPath,
|
|
7231
|
+
schemaName: agent.inputTypeName,
|
|
7232
|
+
typeInfo
|
|
7233
|
+
});
|
|
7234
|
+
}
|
|
7235
|
+
await generateZodArtifacts(sources, {
|
|
7236
|
+
generateFileSource: generateAgentSchemaFileSource,
|
|
7237
|
+
resolversByFile,
|
|
7238
|
+
rootDir,
|
|
7239
|
+
dist
|
|
7240
|
+
});
|
|
7241
|
+
}
|
|
7242
|
+
function generateAgentSchemaFileSource(sources, resolveType, helpersImportPath) {
|
|
7243
|
+
const lines = ["import { z } from 'zod';"];
|
|
7244
|
+
const schemaBlocks = [];
|
|
7245
|
+
for (const source of sources) {
|
|
7246
|
+
if (!source.typeInfo) continue;
|
|
7247
|
+
const block = [`// agent ${source.name} \u2192 ${source.schemaName}`];
|
|
7248
|
+
const schemaCode = generateZodSchemaSource(
|
|
7249
|
+
source.typeInfo,
|
|
7250
|
+
resolveType,
|
|
7251
|
+
source.schemaName,
|
|
7252
|
+
false
|
|
7253
|
+
).replace(/^import \{ z \} from 'zod';\s*\n\s*\n/, "");
|
|
7254
|
+
block.push(schemaCode);
|
|
7255
|
+
block.push("");
|
|
7256
|
+
schemaBlocks.push(block.join("\n"));
|
|
7257
|
+
}
|
|
7258
|
+
const allSchemaCode = schemaBlocks.join("\n");
|
|
7259
|
+
if (helpersImportPath && usesCoerceHelpers(allSchemaCode)) {
|
|
7260
|
+
lines.push(
|
|
7261
|
+
`import { coerceNumber, coerceBoolean, coerceMap, coerceSet } from '${helpersImportPath}';`
|
|
7262
|
+
);
|
|
7263
|
+
}
|
|
7264
|
+
lines.push("");
|
|
7265
|
+
lines.push(...schemaBlocks);
|
|
7266
|
+
return lines.join("\n").replace(/\n+$/, "\n");
|
|
7267
|
+
}
|
|
7158
7268
|
|
|
7159
7269
|
// src/cli/generateTaskArtifacts.ts
|
|
7160
7270
|
init_generateZodArtifacts();
|