This commit is contained in:
Suraj Anand 2026-01-29 21:53:35 -05:00 committed by GitHub
commit 5d6f53048b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 76 additions and 1 deletions

View File

@ -36,6 +36,7 @@ export type HookMappingConfig = {
thinking?: string; thinking?: string;
timeoutSeconds?: number; timeoutSeconds?: number;
transform?: HookMappingTransform; transform?: HookMappingTransform;
agentId?: string;
}; };
export type HooksGmailTailscaleMode = "off" | "serve" | "funnel"; export type HooksGmailTailscaleMode = "off" | "serve" | "funnel";

View File

@ -22,6 +22,7 @@ export type HookMappingResolved = {
thinking?: string; thinking?: string;
timeoutSeconds?: number; timeoutSeconds?: number;
transform?: HookMappingTransformResolved; transform?: HookMappingTransformResolved;
agentId?: string;
}; };
export type HookMappingTransformResolved = { export type HookMappingTransformResolved = {
@ -55,6 +56,7 @@ export type HookAction =
model?: string; model?: string;
thinking?: string; thinking?: string;
timeoutSeconds?: number; timeoutSeconds?: number;
agentId?: string;
}; };
export type HookMappingResult = export type HookMappingResult =

View File

@ -137,6 +137,7 @@ export type HookAgentPayload = {
model?: string; model?: string;
thinking?: string; thinking?: string;
timeoutSeconds?: number; timeoutSeconds?: number;
agentId?: string;
}; };
const listHookChannelValues = () => ["last", ...listChannelPlugins().map((plugin) => plugin.id)]; const listHookChannelValues = () => ["last", ...listChannelPlugins().map((plugin) => plugin.id)];
@ -195,7 +196,9 @@ export function normalizeAgentPayload(
const timeoutSeconds = const timeoutSeconds =
typeof timeoutRaw === "number" && Number.isFinite(timeoutRaw) && timeoutRaw > 0 typeof timeoutRaw === "number" && Number.isFinite(timeoutRaw) && timeoutRaw > 0
? Math.floor(timeoutRaw) ? Math.floor(timeoutRaw)
: undefined; : un
const agentIdRaw = payload.agentId;
const agentId = typeof agentIdRaw === "string" && agentIdRaw.trim() ? agentIdRaw.trim() : undefined;defined;
return { return {
ok: true, ok: true,
value: { value: {
@ -209,6 +212,7 @@ export function normalizeAgentPayload(
model, model,
thinking, thinking,
timeoutSeconds, timeoutSeconds,
agentId,
}, },
}; };
} }

View 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();
}
});
});