Merge c228584de1 into 4583f88626
This commit is contained in:
commit
5d6f53048b
@ -36,6 +36,7 @@ export type HookMappingConfig = {
|
||||
thinking?: string;
|
||||
timeoutSeconds?: number;
|
||||
transform?: HookMappingTransform;
|
||||
agentId?: string;
|
||||
};
|
||||
|
||||
export type HooksGmailTailscaleMode = "off" | "serve" | "funnel";
|
||||
|
||||
@ -22,6 +22,7 @@ export type HookMappingResolved = {
|
||||
thinking?: string;
|
||||
timeoutSeconds?: number;
|
||||
transform?: HookMappingTransformResolved;
|
||||
agentId?: string;
|
||||
};
|
||||
|
||||
export type HookMappingTransformResolved = {
|
||||
@ -55,6 +56,7 @@ export type HookAction =
|
||||
model?: string;
|
||||
thinking?: string;
|
||||
timeoutSeconds?: number;
|
||||
agentId?: string;
|
||||
};
|
||||
|
||||
export type HookMappingResult =
|
||||
|
||||
@ -137,6 +137,7 @@ export type HookAgentPayload = {
|
||||
model?: string;
|
||||
thinking?: string;
|
||||
timeoutSeconds?: number;
|
||||
agentId?: string;
|
||||
};
|
||||
|
||||
const listHookChannelValues = () => ["last", ...listChannelPlugins().map((plugin) => plugin.id)];
|
||||
@ -195,7 +196,9 @@ export function normalizeAgentPayload(
|
||||
const timeoutSeconds =
|
||||
typeof timeoutRaw === "number" && Number.isFinite(timeoutRaw) && timeoutRaw > 0
|
||||
? Math.floor(timeoutRaw)
|
||||
: undefined;
|
||||
: un
|
||||
const agentIdRaw = payload.agentId;
|
||||
const agentId = typeof agentIdRaw === "string" && agentIdRaw.trim() ? agentIdRaw.trim() : undefined;defined;
|
||||
return {
|
||||
ok: true,
|
||||
value: {
|
||||
@ -209,6 +212,7 @@ export function normalizeAgentPayload(
|
||||
model,
|
||||
thinking,
|
||||
timeoutSeconds,
|
||||
agentId,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
68
test/hooks.agentId.test.ts
Normal file
68
test/hooks.agentId.test.ts
Normal file
@ -0,0 +1,68 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { normalizeAgentPayload } from "../src/gateway/hooks.js";
|
||||
|
||||
describe("normalizeAgentPayload agentId support", () => {
|
||||
it("should accept agentId as a string", () => {
|
||||
const payload = {
|
||||
message: "test message",
|
||||
channel: "last",
|
||||
agentId: "agent-123",
|
||||
};
|
||||
const result = normalizeAgentPayload(payload);
|
||||
expect(result.ok).toBe(true);
|
||||
if (result.ok) {
|
||||
expect(result.value.agentId).toBe("agent-123");
|
||||
}
|
||||
});
|
||||
|
||||
it("should trim agentId whitespace", () => {
|
||||
const payload = {
|
||||
message: "test message",
|
||||
channel: "last",
|
||||
agentId: " agent-456 ",
|
||||
};
|
||||
const result = normalizeAgentPayload(payload);
|
||||
expect(result.ok).toBe(true);
|
||||
if (result.ok) {
|
||||
expect(result.value.agentId).toBe("agent-456");
|
||||
}
|
||||
});
|
||||
|
||||
it("should handle missing agentId as undefined", () => {
|
||||
const payload = {
|
||||
message: "test message",
|
||||
channel: "last",
|
||||
};
|
||||
const result = normalizeAgentPayload(payload);
|
||||
expect(result.ok).toBe(true);
|
||||
if (result.ok) {
|
||||
expect(result.value.agentId).toBeUndefined();
|
||||
}
|
||||
});
|
||||
|
||||
it("should ignore empty agentId strings", () => {
|
||||
const payload = {
|
||||
message: "test message",
|
||||
channel: "last",
|
||||
agentId: " ",
|
||||
};
|
||||
const result = normalizeAgentPayload(payload);
|
||||
expect(result.ok).toBe(true);
|
||||
if (result.ok) {
|
||||
expect(result.value.agentId).toBeUndefined();
|
||||
}
|
||||
});
|
||||
|
||||
it("should handle non-string agentId as undefined", () => {
|
||||
const payload = {
|
||||
message: "test message",
|
||||
channel: "last",
|
||||
agentId: 123,
|
||||
} as any;
|
||||
const result = normalizeAgentPayload(payload);
|
||||
expect(result.ok).toBe(true);
|
||||
if (result.ok) {
|
||||
expect(result.value.agentId).toBeUndefined();
|
||||
}
|
||||
});
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user