@agentrq/acp-gateway 0.2.3 → 0.2.4

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.
@@ -0,0 +1,118 @@
1
+ /**
2
+ * registry.ts
3
+ *
4
+ * Resolves ACP agents from the public registry, so an agent can be named by id
5
+ * instead of being installed and wired up by hand.
6
+ *
7
+ * The registry publishes one index of every agent it lists, each entry saying
8
+ * how the agent is distributed: an npm package run through `npx`, a PyPI
9
+ * package run through `uvx`, or a platform-specific binary to download.
10
+ *
11
+ * See https://github.com/agentclientprotocol/registry
12
+ */
13
+ /** The registry index, as published by the ACP project. */
14
+ export const DEFAULT_REGISTRY_URL = "https://cdn.agentclientprotocol.com/registry/v1/latest/registry.json";
15
+ /** Node's platform/arch names mapped onto the registry's identifiers. */
16
+ const PLATFORMS = { darwin: "darwin", linux: "linux", win32: "windows" };
17
+ const ARCHITECTURES = { arm64: "aarch64", x64: "x86_64" };
18
+ /**
19
+ * The registry platform identifier for the machine we are running on, or
20
+ * undefined where the registry publishes nothing for it.
21
+ */
22
+ export function hostPlatformTarget(platform = process.platform, arch = process.arch) {
23
+ const os = PLATFORMS[platform];
24
+ const cpu = ARCHITECTURES[arch];
25
+ if (!os || !cpu)
26
+ return undefined;
27
+ return `${os}-${cpu}`;
28
+ }
29
+ /** Rejects anything that is not a registry index, so a bad URL fails loudly. */
30
+ function assertRegistry(value, url) {
31
+ const agents = value?.agents;
32
+ if (!Array.isArray(agents)) {
33
+ throw new Error(`${url} did not return an ACP registry index.`);
34
+ }
35
+ }
36
+ /**
37
+ * Downloads the registry index.
38
+ *
39
+ * `fetchImpl` and `url` are injectable so a pinned or local registry can be
40
+ * used instead of the published one.
41
+ */
42
+ export async function fetchRegistry(url = DEFAULT_REGISTRY_URL, fetchImpl = fetch) {
43
+ const response = await fetchImpl(url);
44
+ if (!response.ok) {
45
+ throw new Error(`Failed to fetch the ACP registry from ${url}: ${response.status} ${response.statusText}`);
46
+ }
47
+ const body = await response.json();
48
+ assertRegistry(body, url);
49
+ return body;
50
+ }
51
+ /** Finds one agent by its registry id. */
52
+ export function findAgent(registry, id) {
53
+ return registry.agents.find((agent) => agent.id === id);
54
+ }
55
+ /**
56
+ * Renders the registry as a table for the terminal.
57
+ *
58
+ * `target` is passed in rather than defaulted, so that "this machine has no
59
+ * published build" stays distinguishable from "caller did not say".
60
+ */
61
+ export function describeAgents(registry, target) {
62
+ const rows = registry.agents.map((agent) => {
63
+ const kinds = availableKinds(agent, target);
64
+ const support = kinds.length ? kinds.join(", ") : "unavailable on this platform";
65
+ return ` ${agent.id.padEnd(22)} ${agent.name} — ${support}`;
66
+ });
67
+ return rows.join("\n");
68
+ }
69
+ /** Which distributions of this agent can actually run on this machine. */
70
+ export function availableKinds(agent, target) {
71
+ const kinds = [];
72
+ if (agent.distribution.npx)
73
+ kinds.push("npx");
74
+ if (agent.distribution.uvx)
75
+ kinds.push("uvx");
76
+ if (target && agent.distribution.binary?.[target])
77
+ kinds.push("binary");
78
+ return kinds;
79
+ }
80
+ /**
81
+ * Picks the binary build for this machine.
82
+ *
83
+ * Throws rather than falling back to another platform's build: running the
84
+ * wrong architecture would fail in a much more confusing way.
85
+ */
86
+ export function selectBinaryTarget(agent, target) {
87
+ const binary = agent.distribution.binary;
88
+ if (!binary) {
89
+ throw new Error(`Agent "${agent.id}" publishes no binary distribution.`);
90
+ }
91
+ if (!target) {
92
+ throw new Error(`The ACP registry publishes no binaries for ${process.platform}/${process.arch}.`);
93
+ }
94
+ const selected = binary[target];
95
+ if (!selected) {
96
+ throw new Error(`Agent "${agent.id}" publishes no binary for ${target} ` +
97
+ `(available: ${Object.keys(binary).join(", ")}).`);
98
+ }
99
+ return selected;
100
+ }
101
+ /**
102
+ * Turns an npm or PyPI distribution into the command that runs it.
103
+ *
104
+ * On Windows npm installs `npx` as `npx.cmd`; spawning a bare "npx" there
105
+ * looks only for `npx.exe` and fails, so the runner is named explicitly.
106
+ */
107
+ export function packageLaunchSpec(kind, distribution, platform = process.platform) {
108
+ // `npx -y` skips the install prompt, which would otherwise block a gateway
109
+ // that nobody is watching.
110
+ const args = kind === "npx" ? ["-y", distribution.package] : [distribution.package];
111
+ return {
112
+ command: kind === "npx" && platform === "win32" ? "npx.cmd" : kind,
113
+ args: [...args, ...(distribution.args ?? [])],
114
+ env: distribution.env,
115
+ kind,
116
+ };
117
+ }
118
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,2DAA2D;AAC3D,MAAM,CAAC,MAAM,oBAAoB,GAC/B,sEAAsE,CAAC;AA4DzE,yEAAyE;AACzE,MAAM,SAAS,GAA2B,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;AACjG,MAAM,aAAa,GAA2B,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC;AAElF;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAChC,QAAQ,GAAW,OAAO,CAAC,QAAQ,EACnC,IAAI,GAAW,OAAO,CAAC,IAAI;IAE3B,MAAM,EAAE,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;IAC/B,MAAM,GAAG,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;IAChC,IAAI,CAAC,EAAE,IAAI,CAAC,GAAG;QAAE,OAAO,SAAS,CAAC;IAClC,OAAO,GAAG,EAAE,IAAI,GAAG,EAAoB,CAAC;AAC1C,CAAC;AAED,gFAAgF;AAChF,SAAS,cAAc,CAAC,KAAc,EAAE,GAAW;IACjD,MAAM,MAAM,GAAI,KAAqC,EAAE,MAAM,CAAC;IAC9D,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CAAC,GAAG,GAAG,wCAAwC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B,CAC/B,IAAmB,EACnB,YAAiC,EACjC,QAAQ,GAAW,OAAO,CAAC,QAAQ;IAEnC,2EAA2E;IAC3E,2BAA2B;IAC3B,MAAM,IAAI,GAAG,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IACpF,OAAO;QACL,OAAO,EAAE,IAAI,KAAK,KAAK,IAAI,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI;QAClE,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,CAAC,YAAY,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;QAC7C,GAAG,EAAE,YAAY,CAAC,GAAG;QACrB,IAAI;KACL,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentrq/acp-gateway",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "ACP+MCP bridge CLI for agentrq workspaces",
5
5
  "type": "module",
6
6
  "publishConfig": {