@faapi/faapi 5.3.0 → 6.0.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/index.d.ts CHANGED
@@ -419,15 +419,24 @@ interface AgentConfig {
419
419
  * 可见性过滤(authHooks):LLM 可见 tools 清单组装完成后调用,
420
420
  * 返回过滤后的数组(含 agent-as-tool 项)。每次 agent.run / stream 生效——
421
421
  * 无权 tool 不进 LLM 视野,比执行时拒绝省一轮 LLM 调用。
422
+ *
423
+ * tools 为 OpenAI chat completions 规范形(`type: 'function'` +
424
+ * `function: { name, description?, parameters? }`),按 `tool.function.name` 过滤。
422
425
  */
423
426
  filterTools?: (tools: Array<{
424
- name: string;
425
- description?: string;
426
- input: Record<string, unknown>;
427
+ type: 'function';
428
+ function: {
429
+ name: string;
430
+ description?: string;
431
+ parameters?: Record<string, unknown>;
432
+ };
427
433
  }>, ctx: FaapiContext | undefined) => Array<{
428
- name: string;
429
- description?: string;
430
- input: Record<string, unknown>;
434
+ type: 'function';
435
+ function: {
436
+ name: string;
437
+ description?: string;
438
+ parameters?: Record<string, unknown>;
439
+ };
431
440
  }>;
432
441
  }
433
442
  /**
@@ -1368,6 +1377,17 @@ interface InjectOptions {
1368
1377
  path?: string;
1369
1378
  headers?: Record<string, string>;
1370
1379
  query?: Record<string, string>;
1380
+ /**
1381
+ * 请求体,语义按类型区分(与 fastify inject 约定一致):
1382
+ * - `string` / `Buffer` / `Uint8Array`:原样透传不二次编码(默认 content-type
1383
+ * 分别为 `text/plain` / `application/octet-stream`)
1384
+ * - 其他值(对象/数组等):`JSON.stringify` 后发送,默认 content-type `application/json`
1385
+ *
1386
+ * 调用方显式传入的 `content-type` 头优先于默认值(string body +
1387
+ * `application/x-www-form-urlencoded` 可直接测 form 表单路由)。
1388
+ * 注意不要把 `JSON.stringify` 的结果当对象传——那会作为原始文本再被服务端
1389
+ * JSON 解析一次,得到字符串而非对象。
1390
+ */
1371
1391
  body?: unknown;
1372
1392
  }
1373
1393
  interface InjectResponse {
package/dist/index.js CHANGED
@@ -5890,13 +5890,28 @@ async function createAppBase(options) {
5890
5890
  reject(new Error("No request handler found"));
5891
5891
  return;
5892
5892
  }
5893
- const mockReq = Readable3.from(body !== void 0 ? [Buffer.from(JSON.stringify(body))] : []);
5893
+ let payload;
5894
+ let defaultContentType;
5895
+ if (body !== void 0) {
5896
+ if (typeof body === "string") {
5897
+ payload = Buffer.from(body, "utf-8");
5898
+ defaultContentType = "text/plain";
5899
+ } else if (body instanceof Uint8Array) {
5900
+ payload = Buffer.from(body);
5901
+ defaultContentType = "application/octet-stream";
5902
+ } else {
5903
+ payload = Buffer.from(JSON.stringify(body));
5904
+ defaultContentType = "application/json";
5905
+ }
5906
+ }
5907
+ const mockReq = Readable3.from(payload !== void 0 ? [payload] : []);
5894
5908
  mockReq.method = method;
5895
5909
  mockReq.url = `${reqPath}${queryStr}`;
5910
+ const hasCallerContentType = "content-type" in reqHeaders || "Content-Type" in reqHeaders;
5896
5911
  mockReq.headers = {
5897
5912
  ...reqHeaders,
5898
5913
  host: "localhost",
5899
- "content-type": body !== void 0 ? "application/json" : void 0
5914
+ ...payload !== void 0 && !hasCallerContentType ? { "content-type": defaultContentType } : {}
5900
5915
  };
5901
5916
  mockReq.socket = { remoteAddress: "127.0.0.1" };
5902
5917
  handler(