@app-vitals/agent-admin 1.100.0 → 1.101.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@app-vitals/agent-admin",
3
- "version": "1.100.0",
3
+ "version": "1.101.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/app-vitals/agent.git",
@@ -44,7 +44,7 @@
44
44
  },
45
45
  "dependencies": {
46
46
  "@anthropic-ai/sdk": "0.137.0",
47
- "@app-vitals/agent-lib": "1.100.0",
47
+ "@app-vitals/agent-lib": "1.101.0",
48
48
  "@hono/zod-openapi": "^1.0.0",
49
49
  "@prisma/adapter-pg": "^7.10.0",
50
50
  "@prisma/client": "^7.10.0",
@@ -0,0 +1,39 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { createAgentAccessChecks } from "./admin-ui.ts";
3
+
4
+ const unsorted = [
5
+ { id: "3", name: "zeta" },
6
+ { id: "2", name: "Alpha" },
7
+ { id: "1", name: "alpha" },
8
+ { id: "4", name: "Beta" },
9
+ ];
10
+ const expected = ["1", "2", "4", "3"];
11
+
12
+ function make() {
13
+ const all = [...unsorted];
14
+ const checks = createAgentAccessChecks({
15
+ agentService: {
16
+ listAll: async () => all,
17
+ listByIds: async () => all,
18
+ } as never,
19
+ callerScopeResolver: (async () => ({
20
+ kind: "agents",
21
+ agentIds: ["1"],
22
+ })) as never,
23
+ });
24
+ return { checks, all };
25
+ }
26
+
27
+ describe("resolveAccessibleAgents ordering", () => {
28
+ test("admin path sorts case-insensitively by name, id tiebreak", async () => {
29
+ const { checks, all } = make();
30
+ const out = await checks.resolveAccessibleAgents("a@x.com", true);
31
+ expect(out.map((a) => a.id)).toEqual(expected);
32
+ expect(all.map((a) => a.id)).toEqual(["3", "2", "1", "4"]);
33
+ });
34
+ test("non-admin path sorts the same way", async () => {
35
+ const { checks } = make();
36
+ const out = await checks.resolveAccessibleAgents("a@x.com", false);
37
+ expect(out.map((a) => a.id)).toEqual(expected);
38
+ });
39
+ });
package/src/admin-ui.ts CHANGED
@@ -861,11 +861,22 @@ export function createHtmlResponder(appBaseUrl: string): AdminHtmlResponder {
861
861
 
862
862
  // ─── Agent access ─────────────────────────────────────────────────────────────
863
863
 
864
+ /** Case-insensitive name order, id as stable tiebreak; returns a new array. */
865
+ function sortAgentsByName<T extends { id: string; name: string }>(
866
+ agents: readonly T[],
867
+ ): T[] {
868
+ return [...agents].sort(
869
+ (a, b) =>
870
+ a.name.localeCompare(b.name, undefined, { sensitivity: "base" }) ||
871
+ a.id.localeCompare(b.id),
872
+ );
873
+ }
874
+
864
875
  /**
865
876
  * Agent access checks shared by the platform UI and extension UIs (AEP-3.2).
866
877
  * resolveAccessibleAgents: admins see the full fleet, non-admins only the
867
- * agents in their caller scope (no ordering beyond what listAll()/listByIds()
868
- * return). assertAgentAccess: admins always, others when the agent is in scope.
878
+ * agents in their caller scope; both are sorted case-insensitively by name
879
+ * (id tiebreak). assertAgentAccess: admins always, others when the agent is in scope.
869
880
  */
870
881
  export function createAgentAccessChecks(deps: {
871
882
  agentService: Pick<AgentService, "listAll" | "listByIds">;
@@ -878,10 +889,14 @@ export function createAgentAccessChecks(deps: {
878
889
  isAdmin: boolean,
879
890
  ): Promise<Awaited<ReturnType<AgentService["listAll"]>>> {
880
891
  if (isAdmin) {
881
- return agentService.listAll();
892
+ return sortAgentsByName(await agentService.listAll());
882
893
  }
883
894
  const scope = await callerScopeResolver(userEmail, false);
884
- return agentService.listByIds(scope.kind === "all" ? [] : scope.agentIds);
895
+ return sortAgentsByName(
896
+ await agentService.listByIds(
897
+ scope.kind === "all" ? [] : scope.agentIds,
898
+ ),
899
+ );
885
900
  },
886
901
  async assertAgentAccess(
887
902
  agentId: string,