mirror of
https://github.com/getpaseo/paseo.git
synced 2026-07-29 12:01:31 +00:00
Keep delegated agents out of workspace alerts (#1293)
* Keep delegated agents out of workspace alerts * Share delegated agent label parsing
This commit is contained in:
21
packages/protocol/src/agent-labels.test.ts
Normal file
21
packages/protocol/src/agent-labels.test.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
import {
|
||||
getParentAgentIdFromLabels,
|
||||
isDelegatedAgent,
|
||||
PARENT_AGENT_ID_LABEL,
|
||||
} from "./agent-labels.js";
|
||||
|
||||
describe("agent label policy", () => {
|
||||
test("treats a non-empty parent agent label as delegation", () => {
|
||||
const labels = { [PARENT_AGENT_ID_LABEL]: " parent-agent \n" };
|
||||
|
||||
expect(getParentAgentIdFromLabels(labels)).toBe("parent-agent");
|
||||
expect(isDelegatedAgent({ labels })).toBe(true);
|
||||
});
|
||||
|
||||
test("ignores missing, empty, and non-string parent agent labels", () => {
|
||||
expect(isDelegatedAgent({ labels: {} })).toBe(false);
|
||||
expect(isDelegatedAgent({ labels: { [PARENT_AGENT_ID_LABEL]: " " } })).toBe(false);
|
||||
expect(isDelegatedAgent({ labels: { [PARENT_AGENT_ID_LABEL]: 42 } })).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -1 +1,16 @@
|
||||
export const PARENT_AGENT_ID_LABEL = "paseo.parent-agent-id";
|
||||
|
||||
export interface AgentLabelSource {
|
||||
labels?: Record<string, unknown> | null;
|
||||
}
|
||||
|
||||
export function getParentAgentIdFromLabels(labels: Record<string, unknown> | null | undefined) {
|
||||
const parentAgentId = labels?.[PARENT_AGENT_ID_LABEL];
|
||||
return typeof parentAgentId === "string" && parentAgentId.trim().length > 0
|
||||
? parentAgentId.trim()
|
||||
: null;
|
||||
}
|
||||
|
||||
export function isDelegatedAgent(agent: AgentLabelSource): boolean {
|
||||
return getParentAgentIdFromLabels(agent.labels) !== null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user