@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/dist/cjs/events.js.map +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/registry.js +58 -10
- package/dist/cjs/registry.js.map +1 -1
- package/dist/cjs/server.js +73 -71
- package/dist/cjs/server.js.map +1 -1
- package/dist/events.d.ts +85 -9
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/registry.d.ts +16 -1
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +58 -10
- package/dist/registry.js.map +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +73 -71
- package/dist/server.js.map +1 -1
- package/package.json +1 -1
- package/src/events.ts +83 -9
- package/src/hooks.test.ts +439 -0
- package/src/index.ts +3 -1
- package/src/registry.ts +85 -12
- package/src/server.ts +97 -90
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
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
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
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
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
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
734
|
+
// Apply cursor: skip past afterPath
|
|
735
|
+
if (after) {
|
|
736
|
+
visible = visible.filter((a) => a.path > after.path);
|
|
737
|
+
}
|
|
735
738
|
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
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
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
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:
|