Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Team map hand-offs: the way around never enters the two bots' own cards
AdityaUmale94537c0751db
diff --git a/src/lib/team-canvas-handoffs.test.ts b/src/lib/team-canvas-handoffs.test.tsindex e66a3e145d..0115f6089b 100644--- a/src/lib/team-canvas-handoffs.test.ts+++ b/src/lib/team-canvas-handoffs.test.ts@@ -53,6 +53,22 @@ describe("handoffLines", () => {expect(handoffLines([{ sourceBotId: "a", targetBotId: "b", state: "running" }], stack)[0].path).toBe("M 50 50 C 50 75 50 75 50 100");});+ it("never routes the way around through the giver's or receiver's own card", () => {+ const wide = (x: number, y: number): CardBox => ({ x, y, width: 236, height: 126 });+ const cards = new Map([["from", wide(0, 0)], ["to", wide(500, 80)], ["between", wide(260, 90)]]);+ const [line] = handoffLines([{ sourceBotId: "from", targetBotId: "to", state: "running" }], cards);+ const steps = line.path.match(/-?\d+(\.\d+)?/g)!.map(Number);+ const [sx, sy, ax, ay, bx, by, ex, ey] = steps;+ for (let step = 1; step < 20; step++) {+ const t = step / 20, u = 1 - t;+ const x = u * u * u * sx + 3 * u * u * t * ax + 3 * u * t * t * bx + t * t * t * ex;+ const y = u * u * u * sy + 3 * u * u * t * ay + 3 * u * t * t * by + t * t * t * ey;+ for (const card of cards.values()) {+ expect(x > card.x && x < card.x + card.width && y > card.y && y < card.y + card.height).toBe(false);+ }+ }+ });+it("joins stacked cards bottom to top, and skips bots that are not on the canvas", () => {const lines = handoffLines([{ sourceBotId: "c", targetBotId: "a", state: "connected" },diff --git a/src/lib/team-canvas-handoffs.ts b/src/lib/team-canvas-handoffs.tsindex 2615e26b6c..8b0033ffa6 100644--- a/src/lib/team-canvas-handoffs.ts+++ b/src/lib/team-canvas-handoffs.ts@@ -60,8 +60,8 @@ const curvePoint = ({ start, first, second, end }: Curve, t: number): Point => {const inside = (point: Point, box: CardBox) => point.x > box.x && point.x < box.x + box.width && point.y > box.y && point.y < box.y + box.height;-/** Whether the curve runs through a card it does not start or end at. */-const crossesCards = (curve: Curve, others: CardBox[]) => others.some((box) => {+/** Whether the curve runs through the inside of any of these cards. */+const crossesCards = (curve: Curve, cards: CardBox[]) => cards.some((box) => {for (let step = 1; step < 20; step++) if (inside(curvePoint(curve, step / 20), box)) return true;return false;});@@ -115,7 +115,8 @@ function arrowHead({ second, end, start }: Curve): string {/*** A curved line from the bot handing work on to the bot receiving it, edge to facing edge.- * When that curve would run through another bot's card it goes around the cards instead.+ * When that curve would run through another bot's card it goes around the cards instead,+ * on a way round that enters no card, its own two included.* Running and queued hand-offs end in an arrow at the receiving bot; a plain connection has none.*/export function handoffLines(edges: TeamMapEdge[], boxes: Map<string, CardBox>): HandoffLine[] {@@ -125,7 +126,7 @@ export function handoffLines(edges: TeamMapEdge[], boxes: Map<string, CardBox>):const others = [...boxes].filter(([id]) => id !== edge.sourceBotId && id !== edge.targetBotId).map(([, box]) => box);const direct = directCurve(from, to);const blocking = others.filter((box) => crossesCards(direct, [box]));- const curve = blocking.length ? detours(from, to, blocking).find((route) => !crossesCards(route, others)) ?? direct : direct;+ const curve = blocking.length ? detours(from, to, blocking).find((route) => !crossesCards(route, [from, to, ...others])) ?? direct : direct;const { start, first, second, end } = curve;return [{key: `${edge.sourceBotId}:${edge.targetBotId}`,