@agentsquared/cli 1.0.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.
@@ -0,0 +1,110 @@
1
+ import { signText } from '../runtime/keys.mjs'
2
+ import { utcNow } from '../shared/primitives.mjs'
3
+ import { requestJson } from './http_json.mjs'
4
+
5
+ export function onlineSignTarget(agentId, signedAt) {
6
+ return `agentsquared:relay-online:${agentId}:${signedAt}`
7
+ }
8
+
9
+ export function mcpSignTarget(method, path, agentId, signedAt) {
10
+ return `agentsquared:relay-mcp:${method.toUpperCase()}:${path}:${agentId}:${signedAt}`
11
+ }
12
+
13
+ export async function getBindingDocument(apiBase) {
14
+ return requestJson(`${apiBase}/api/relay/bindings/libp2p-a2a-jsonrpc`)
15
+ }
16
+
17
+ export async function postOnline(apiBase, agentId, bundle, payload) {
18
+ const signedAt = utcNow()
19
+ const body = {
20
+ agentId,
21
+ signedAt,
22
+ signature: signText(bundle, onlineSignTarget(agentId, signedAt)),
23
+ ...payload
24
+ }
25
+ return requestJson(`${apiBase}/api/relay/online`, {
26
+ method: 'POST',
27
+ payload: body
28
+ })
29
+ }
30
+
31
+ export function signedHeaders(method, path, agentId, bundle) {
32
+ const signedAt = utcNow()
33
+ return {
34
+ 'X-AgentSquared-Agent-Id': agentId,
35
+ 'X-AgentSquared-Signed-At': signedAt,
36
+ 'X-AgentSquared-Signature': signText(bundle, mcpSignTarget(method, path, agentId, signedAt))
37
+ }
38
+ }
39
+
40
+ function appendCsv(headers, name, values = []) {
41
+ const cleaned = values.map((value) => `${value}`.trim()).filter(Boolean)
42
+ if (cleaned.length > 0) {
43
+ headers[name] = cleaned.join(',')
44
+ }
45
+ }
46
+
47
+ export function transportRefreshHeaders(transport = null) {
48
+ if (!transport) return {}
49
+ const headers = {}
50
+ const peerId = `${transport.peerId ?? ''}`.trim()
51
+ if (peerId) {
52
+ headers['X-AgentSquared-Peer-Id'] = peerId
53
+ }
54
+ appendCsv(headers, 'X-AgentSquared-Listen-Addrs', transport.listenAddrs ?? [])
55
+ appendCsv(headers, 'X-AgentSquared-Relay-Addrs', transport.relayAddrs ?? [])
56
+ appendCsv(headers, 'X-AgentSquared-Supported-Bindings', transport.supportedBindings ?? [])
57
+ const streamProtocol = `${transport.streamProtocol ?? ''}`.trim()
58
+ if (streamProtocol) {
59
+ headers['X-AgentSquared-Stream-Protocol'] = streamProtocol
60
+ }
61
+ const a2aProtocolVersion = `${transport.a2aProtocolVersion ?? ''}`.trim()
62
+ if (a2aProtocolVersion) {
63
+ headers['X-AgentSquared-A2A-Protocol-Version'] = a2aProtocolVersion
64
+ }
65
+ return headers
66
+ }
67
+
68
+ export async function signedJson(apiBase, method, path, agentId, bundle, payload = null, transport = null) {
69
+ return requestJson(`${apiBase}${path}`, {
70
+ method,
71
+ headers: {
72
+ ...signedHeaders(method, path, agentId, bundle),
73
+ ...transportRefreshHeaders(transport)
74
+ },
75
+ payload: payload == null ? undefined : payload
76
+ })
77
+ }
78
+
79
+ export async function createConnectTicket(apiBase, agentId, bundle, targetAgentId, skillName, transport = null) {
80
+ return signedJson(apiBase, 'POST', '/api/relay/connect-tickets', agentId, bundle, {
81
+ targetAgentId,
82
+ skillName
83
+ }, transport)
84
+ }
85
+
86
+ export async function introspectConnectTicket(apiBase, agentId, bundle, ticket, transport = null) {
87
+ return signedJson(apiBase, 'POST', '/api/relay/connect-tickets/introspect', agentId, bundle, {
88
+ ticket
89
+ }, transport)
90
+ }
91
+
92
+ export async function reportSession(apiBase, agentId, bundle, payload, transport = null) {
93
+ return signedJson(apiBase, 'POST', '/api/relay/session-reports', agentId, bundle, payload, transport)
94
+ }
95
+
96
+ export async function getFriendDirectory(apiBase, agentId, bundle, transport = null) {
97
+ return signedJson(apiBase, 'GET', '/api/relay/friends', agentId, bundle, null, transport)
98
+ }
99
+
100
+ export async function getAgentCard(apiBase, agentId, bundle, targetAgentId, transport = null) {
101
+ return signedJson(
102
+ apiBase,
103
+ 'GET',
104
+ `/api/relay/agents/${encodeURIComponent(targetAgentId)}/.well-known/agent-card.json`,
105
+ agentId,
106
+ bundle,
107
+ null,
108
+ transport
109
+ )
110
+ }
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@agentsquared/cli",
3
+ "version": "1.0.0",
4
+ "description": "Official AgentSquared CLI runtime for onboarding, gateway control, relay access, and OpenClaw host integration.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "bin": {
8
+ "a2-cli": "bin/a2-cli.js"
9
+ },
10
+ "files": [
11
+ "a2_cli.mjs",
12
+ "bin/",
13
+ "lib/",
14
+ "adapters/"
15
+ ],
16
+ "scripts": {
17
+ "self-test": "node ./self_test.mjs",
18
+ "pack:check": "npm pack --dry-run"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/AgentSquaredNet/agentsquared-cli.git"
23
+ },
24
+ "bugs": {
25
+ "url": "https://github.com/AgentSquaredNet/agentsquared-cli/issues"
26
+ },
27
+ "homepage": "https://github.com/AgentSquaredNet/agentsquared-cli#readme",
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "keywords": [
32
+ "agentsquared",
33
+ "cli",
34
+ "openclaw",
35
+ "relay",
36
+ "gateway",
37
+ "libp2p"
38
+ ],
39
+ "dependencies": {
40
+ "@chainsafe/libp2p-yamux": "^8.0.1",
41
+ "@libp2p/autonat": "^3.0.14",
42
+ "@libp2p/circuit-relay-v2": "^4.1.7",
43
+ "@libp2p/crypto": "^5.1.11",
44
+ "@libp2p/dcutr": "^3.0.14",
45
+ "@libp2p/identify": "^4.0.8",
46
+ "@libp2p/noise": "^1.0.1",
47
+ "@libp2p/peer-id": "^5.1.9",
48
+ "@libp2p/tcp": "^11.0.9",
49
+ "@multiformats/multiaddr": "^13.0.1",
50
+ "libp2p": "^3.0.6",
51
+ "ws": "^8.18.0"
52
+ }
53
+ }