@slashfi/agents-sdk 0.35.0 → 0.36.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/src/server.ts CHANGED
@@ -670,101 +670,108 @@ export function createAgentServer(
670
670
  limit: listLimit,
671
671
  cursor: listCursor,
672
672
  } = listAgentsValidate.parse(args);
673
- const agents = registry.list();
674
- let visible = agents.filter((agent) => canSeeAgent(agent, auth));
675
-
676
- // Decode cursor if provided
677
- const after = listCursor
678
- ? (JSON.parse(Buffer.from(listCursor, "base64url").toString()) as {
679
- path: string;
680
- score?: number;
681
- })
682
- : undefined;
683
-
684
- const pageSize = listLimit ?? 20;
685
- let page: typeof visible;
686
- let nextCursor: string | undefined;
687
-
688
- if (listQuery) {
689
- // BM25 search — ranked by score desc, path asc for tie-breaking
690
- const docs = visible.map((agent, i) => ({
691
- id: String(i),
692
- text: [
693
- agent.path,
694
- agent.config?.name ?? "",
695
- agent.config?.description ?? "",
696
- ...agent.tools
697
- .filter((t) => canSeeTool(t, auth))
698
- .map((t) => `${t.name} ${t.description}`),
699
- ].join(" "),
700
- }));
701
- const index = createBM25Index(docs);
702
- const ranked = index.search(listQuery);
703
-
704
- // Build scored list
705
- type ScoredAgent = (typeof visible)[number] & { _score: number };
706
- let scored: ScoredAgent[] = ranked.map((r) => ({
707
- ...visible[Number(r.id)],
708
- _score: r.score,
709
- }));
710
673
 
711
- // Apply cursor: skip past the after position
712
- if (after?.score !== undefined) {
713
- scored = scored.filter(
714
- (a) =>
715
- a._score < after.score! ||
716
- (a._score === after.score! && a.path > after.path),
717
- );
718
- }
674
+ const result = await registry.listAgents(
675
+ { query: listQuery, limit: listLimit, cursor: listCursor },
676
+ async (allAgents) => {
677
+ let visible = allAgents.filter((agent) => canSeeAgent(agent, auth));
678
+
679
+ // Decode cursor if provided
680
+ const after = listCursor
681
+ ? (JSON.parse(Buffer.from(listCursor, "base64url").toString()) as {
682
+ path: string;
683
+ score?: number;
684
+ })
685
+ : undefined;
686
+
687
+ const pageSize = listLimit ?? 20;
688
+ let page: typeof visible;
689
+ let nextCursor: string | undefined;
690
+
691
+ if (listQuery) {
692
+ // BM25 search — ranked by score desc, path asc for tie-breaking
693
+ const docs = visible.map((agent, i) => ({
694
+ id: String(i),
695
+ text: [
696
+ agent.path,
697
+ agent.config?.name ?? "",
698
+ agent.config?.description ?? "",
699
+ ...agent.tools
700
+ .filter((t) => canSeeTool(t, auth))
701
+ .map((t) => `${t.name} ${t.description}`),
702
+ ].join(" "),
703
+ }));
704
+ const index = createBM25Index(docs);
705
+ const ranked = index.search(listQuery);
706
+
707
+ // Build scored list
708
+ type ScoredAgent = (typeof visible)[number] & { _score: number };
709
+ let scored: ScoredAgent[] = ranked.map((r) => ({
710
+ ...visible[Number(r.id)],
711
+ _score: r.score,
712
+ }));
713
+
714
+ // Apply cursor: skip past the after position
715
+ if (after?.score !== undefined) {
716
+ scored = scored.filter(
717
+ (a) =>
718
+ a._score < after.score! ||
719
+ (a._score === after.score! && a.path > after.path),
720
+ );
721
+ }
719
722
 
720
- page = scored.slice(0, pageSize);
721
- if (scored.length > pageSize) {
722
- const last = scored[pageSize - 1] as ScoredAgent;
723
- nextCursor = Buffer.from(
724
- JSON.stringify({ path: last.path, score: last._score }),
725
- ).toString("base64url");
726
- }
727
- } else {
728
- // Alphabetical listing — sorted by path
729
- visible.sort((a, b) => a.path.localeCompare(b.path));
723
+ page = scored.slice(0, pageSize);
724
+ if (scored.length > pageSize) {
725
+ const last = scored[pageSize - 1] as ScoredAgent;
726
+ nextCursor = Buffer.from(
727
+ JSON.stringify({ path: last.path, score: last._score }),
728
+ ).toString("base64url");
729
+ }
730
+ } else {
731
+ // Alphabetical listing — sorted by path
732
+ visible.sort((a, b) => a.path.localeCompare(b.path));
730
733
 
731
- // Apply cursor: skip past afterPath
732
- if (after) {
733
- visible = visible.filter((a) => a.path > after.path);
734
- }
734
+ // Apply cursor: skip past afterPath
735
+ if (after) {
736
+ visible = visible.filter((a) => a.path > after.path);
737
+ }
735
738
 
736
- page = visible.slice(0, pageSize);
737
- if (visible.length > pageSize) {
738
- const last = page[page.length - 1];
739
- nextCursor = Buffer.from(
740
- JSON.stringify({ path: last.path }),
741
- ).toString("base64url");
742
- }
743
- }
739
+ page = visible.slice(0, pageSize);
740
+ if (visible.length > pageSize) {
741
+ const last = page[page.length - 1];
742
+ nextCursor = Buffer.from(
743
+ JSON.stringify({ path: last.path }),
744
+ ).toString("base64url");
745
+ }
746
+ }
744
747
 
745
- return mcpResult({
746
- success: true,
747
- total: agents.filter((a) => canSeeAgent(a, auth)).length,
748
- nextCursor,
749
- agents: page.map((agent) => ({
750
- path: agent.path,
751
- name: agent.config?.name,
752
- description: agent.config?.description,
753
- supportedActions: agent.config?.supportedActions,
754
- integration: agent.config?.integration || null,
755
- security: agent.config?.security
756
- ? { type: agent.config.security.type }
757
- : undefined,
758
- resources: agent.config?.resources?.map((r) => ({
759
- uri: r.uri,
760
- name: r.name,
761
- mimeType: r.mimeType,
762
- })),
763
- tools: agent.tools
764
- .filter((t) => canSeeTool(t, auth))
765
- .map((t) => t.name),
766
- })),
767
- });
748
+ return {
749
+ success: true as const,
750
+ total: allAgents.filter((a) => canSeeAgent(a, auth)).length,
751
+ nextCursor,
752
+ agents: page.map((agent) => ({
753
+ path: agent.path,
754
+ name: agent.config?.name,
755
+ description: agent.config?.description,
756
+ supportedActions: agent.config?.supportedActions,
757
+ integration: agent.config?.integration || null,
758
+ security: agent.config?.security
759
+ ? { type: agent.config.security.type }
760
+ : undefined,
761
+ resources: agent.config?.resources?.map((r) => ({
762
+ uri: r.uri,
763
+ name: r.name,
764
+ mimeType: r.mimeType,
765
+ })),
766
+ tools: agent.tools
767
+ .filter((t) => canSeeTool(t, auth))
768
+ .map((t) => t.name),
769
+ })),
770
+ };
771
+ },
772
+ );
773
+
774
+ return mcpResult(result);
768
775
  }
769
776
 
770
777
  default: