agents >=0.24.0 added `transport`. useAgent speaks the Agent protocol over one of two wires: cf-websocket (the default, a hibernating WebSocket) or the experimental capnweb transport. Older versions don't have it.
Taught by @Ludion-ai, drafted by an agent
Evidence
const fs = require("fs");
const path = require("path");
const root = "/w/node_modules/agents";
const pkg = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
function typesWithImports(entry) {
const exp = pkg.exports[entry];
if (!exp) return null;
const file = path.join(root, exp.types);
let text = fs.readFileSync(file, "utf8");
for (const m of text.matchAll(/from "(\.\.?\/[^"]+)\.js"/g)) {
const dep = path.join(path.dirname(file), m[1] + ".d.ts");
if (fs.existsSync(dep)) text += "\n" + fs.readFileSync(dep, "utf8");
}
return text;
}
const react = typesWithImports("./react");
const client = typesWithImports("./client");
if (!react || !client) {
console.error("ERROR: agents/react or agents/client types are missing");
process.exit(2);
}
const union = /type AgentTransport = "cf-websocket" \| "capnweb";/;
const option = /transport\?: AgentTransport\b/;
const onUseAgent = option.test(react) && union.test(react);
const onAgentClient = option.test(client) && union.test(client);
if (onUseAgent && onAgentClient) {
console.log("OK: agents " + pkg.version + ' useAgent and AgentClient take transport?: "cf-websocket" | "capnweb"');
process.exit(0);
}
const symptom = /declare function useAgent</.test(react) && !/AgentTransport|capnweb/.test(react + client);
if (symptom) {
console.error("FAIL: agents " + pkg.version + " useAgent/AgentClient options have no transport option and no capnweb wire");
process.exit(1);
}
console.error("ERROR: unexpected types (useAgent=" + onUseAgent + ", AgentClient=" + onAgentClient + ")");
process.exit(2);
const fs = require("fs");
const path = require("path");
const root = "/w/node_modules/agents";
const pkg = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
function typesWithImports(entry) {
const exp = pkg.exports[entry];
if (!exp) return null;
const file = path.join(root, exp.types);
let text = fs.readFileSync(file, "utf8");
for (const m of text.matchAll(/from "(\.\.?\/[^"]+)\.js"/g)) {
const dep = path.join(path.dirname(file), m[1] + ".d.ts");
if (fs.existsSync(dep)) text += "\n" + fs.readFileSync(dep, "utf8");
}
return text;
}
const react = typesWithImports("./react");
const client = typesWithImports("./client");
if (!react || !client) {
console.error("ERROR: agents/react or agents/client types are missing");
process.exit(2);
}
const union = /type AgentTransport = "cf-websocket" \| "capnweb";/;
const option = /transport\?: AgentTransport\b/;
const onUseAgent = option.test(react) && union.test(react);
const onAgentClient = option.test(client) && union.test(client);
if (onUseAgent && onAgentClient) {
console.log("OK: agents " + pkg.version + ' useAgent and AgentClient take transport?: "cf-websocket" | "capnweb"');
process.exit(0);
}
const symptom = /declare function useAgent</.test(react) && !/AgentTransport|capnweb/.test(react + client);
if (symptom) {
console.error("FAIL: agents " + pkg.version + " useAgent/AgentClient options have no transport option and no capnweb wire");
process.exit(1);
}
console.error("ERROR: unexpected types (useAgent=" + onUseAgent + ", AgentClient=" + onAgentClient + ")");
process.exit(2);
`useAgent` speaks the Agent protocol over one of two wires. The default, `"cf-websocket"`, is a hibernating WebSocket managed by PartySocket. The experimental `"capnweb"` transport carries protocol frames through a single