@slashfi/agents-sdk 0.90.0 → 0.90.2

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.
@@ -538,6 +538,60 @@ describe("Secret URI resolution", () => {
538
538
  });
539
539
  });
540
540
 
541
+ // ─── Basic Auth Tests ────────────────────────────────────────────
542
+
543
+ describe("Registry Consumer — Basic Auth", () => {
544
+ let server: AgentServer;
545
+ const PORT = 19895;
546
+ const USERNAME = "ashby-api-key";
547
+ const PASSWORD = "";
548
+
549
+ beforeAll(async () => {
550
+ const registry = createAgentRegistry();
551
+ registry.register(mathAgent);
552
+ registry.register(echoAgent);
553
+
554
+ server = createAgentServer(registry, {
555
+ port: PORT,
556
+ resolveAuth: async (req) => {
557
+ const auth = req.headers.get("authorization");
558
+ const expected = `Basic ${Buffer.from(`${USERNAME}:${PASSWORD}`, "utf8").toString("base64")}`;
559
+ if (auth === expected) {
560
+ return {
561
+ callerId: "basic-auth-user",
562
+ callerType: "system" as const,
563
+ scopes: ["*"],
564
+ };
565
+ }
566
+ return null;
567
+ },
568
+ });
569
+ await server.start();
570
+ });
571
+
572
+ afterAll(async () => {
573
+ await server.stop();
574
+ });
575
+
576
+ test("consumer with basic auth type can list agents", async () => {
577
+ const consumer = await createRegistryConsumer({
578
+ registries: [
579
+ {
580
+ url: `http://localhost:${PORT}`,
581
+ auth: { type: "basic", username: USERNAME, password: PASSWORD },
582
+ },
583
+ ],
584
+ refs: [{ ref: "@math" }],
585
+ });
586
+
587
+ const agents = await consumer.list();
588
+ expect(agents.length).toBeGreaterThanOrEqual(2);
589
+ const paths = agents.map((a) => a.path);
590
+ expect(paths).toContain("@math");
591
+ expect(paths).toContain("@echo");
592
+ });
593
+ });
594
+
541
595
  // ─── API Key Auth Tests ──────────────────────────────────────────
542
596
 
543
597
  describe("Registry Consumer — API Key Auth", () => {
@@ -31,6 +31,7 @@
31
31
  export type RegistryAuth =
32
32
  | { type: "none" }
33
33
  | { type: "bearer"; token?: string; tokenUrl?: string }
34
+ | { type: "basic"; username?: string; password?: string }
34
35
  | { type: "api-key"; key?: string; header?: string }
35
36
  | { type: "jwt"; issuer?: string };
36
37
 
@@ -144,7 +144,7 @@ function expandEnvVars(value: string): string {
144
144
 
145
145
  /**
146
146
  * Build auth headers for a registry based on its auth config and custom headers.
147
- * Merges typed auth (bearer, api-key) with arbitrary custom headers.
147
+ * Merges typed auth (bearer, basic, api-key) with arbitrary custom headers.
148
148
  * Environment variable references ($VAR or ${VAR}) in header values are expanded.
149
149
  */
150
150
  function buildRegistryAuthHeaders(
@@ -162,6 +162,15 @@ function buildRegistryAuthHeaders(
162
162
  }
163
163
  break;
164
164
  }
165
+ case "basic": {
166
+ if ("username" in registry.auth && registry.auth.username) {
167
+ const password = ("password" in registry.auth ? registry.auth.password : undefined) ?? "";
168
+ const credentials = `${registry.auth.username}:${password}`;
169
+ const encoded = Buffer.from(credentials, "utf8").toString("base64");
170
+ headers.Authorization = `Basic ${encoded}`;
171
+ }
172
+ break;
173
+ }
165
174
  case "api-key": {
166
175
  if ("key" in registry.auth && registry.auth.key) {
167
176
  const headerName = ("header" in registry.auth ? registry.auth.header : undefined) ?? "x-api-key";