Merge c228584de1 into 4583f88626
This commit is contained in:
commit
5d6f53048b
@ -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";
|
||||||
|
|||||||
@ -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 =
|
||||||
|
|||||||
@ -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,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
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